Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following organizations or individuals have contributed to ScanCode:
- François Granade @farialima
- Frank Viernau @fviernau
- Gaurang Rao @Gaupeng
- Hakan Dilek @hakandilek
- Hanif Ali @hanif-ali
- Horie Issei @is2ei
- James Ward @jamesward
Expand Down
48 changes: 48 additions & 0 deletions tests/scancode/test_pool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/scancode-toolkit for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#

import multiprocessing

import pytest

from commoncode.system import on_linux
from licensedcode import cache
from scancode.pool import get_pool


PARENT_CACHE_SENTINEL = 'parent-warmed-license-cache'


def _get_worker_license_cache_state():
"""
Return the worker's license cache singleton state and multiprocessing start
method.
"""
from licensedcode import cache

return cache._LICENSE_CACHE, multiprocessing.get_start_method()


@pytest.mark.skipif(not on_linux, reason='Linux-only multiprocessing default')
def test_license_cache_warmup_is_inherited_by_pool_workers(monkeypatch):
"""
ScanCode warms the license cache before creating its process pool so forked
child processes inherit the loaded index instead of loading private copies.
"""
monkeypatch.setattr(cache, '_LICENSE_CACHE', PARENT_CACHE_SENTINEL)

with get_pool(processes=1) as scan_pool:
worker_cache_state, worker_start_method = scan_pool.apply(
_get_worker_license_cache_state,
)

assert worker_cache_state == PARENT_CACHE_SENTINEL, (
'Pool worker did not inherit the parent-warmed license cache. '
f'Worker start method was {worker_start_method!r}.'
)
Loading