Skip to content

Commit 0e1d2e9

Browse files
committed
fix(tests): address PR #274 review feedback
- Rename TestNEW1_EnsureInitializedRace to TestEnsureInitializedRace - Update docstring to describe regression guard, not pre-fix state - Replace asyncio.sleep(0.05) with explicit deploy_entered Event
1 parent 3ac029e commit 0e1d2e9

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

tests/bug_probes/test_class_execution.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import pytest
77

88

9-
class TestNEW1_EnsureInitializedRace:
10-
"""AE-2370: _ensure_initialized has no async lock — concurrent calls cause double deploy.
9+
class TestEnsureInitializedRace:
10+
"""AE-2370: concurrent _ensure_initialized calls must not double-deploy.
1111
12-
Without a lock, two concurrent calls to _ensure_initialized both pass
13-
the `if not self._initialized` check and both call get_or_deploy_resource,
14-
causing a double deploy and orphaning one stub.
12+
Regression guard: without the async lock added in this PR, two concurrent
13+
calls both pass the `if not self._initialized` check and both call
14+
get_or_deploy_resource, causing a double deploy and orphaning one stub.
1515
"""
1616

1717
@pytest.fixture
@@ -41,7 +41,6 @@ def predict(self, x):
4141
dependencies=None,
4242
system_dependencies=None,
4343
accelerate_downloads=False,
44-
extra={},
4544
)
4645
instance = wrapper_cls()
4746

@@ -51,11 +50,13 @@ def predict(self, x):
5150
async def test_concurrent_calls_deploy_only_once(self, wrapper_instance):
5251
"""Two concurrent _ensure_initialized calls must call get_or_deploy_resource exactly once."""
5352
deploy_call_count = 0
53+
deploy_entered = asyncio.Event()
5454
gate = asyncio.Event()
5555

5656
async def slow_deploy(config):
5757
nonlocal deploy_call_count
5858
deploy_call_count += 1
59+
deploy_entered.set()
5960
await gate.wait()
6061
return MagicMock()
6162

@@ -70,7 +71,7 @@ async def slow_deploy(config):
7071
task1 = asyncio.create_task(wrapper_instance._ensure_initialized())
7172
task2 = asyncio.create_task(wrapper_instance._ensure_initialized())
7273

73-
await asyncio.sleep(0.05)
74+
await deploy_entered.wait()
7475
gate.set()
7576

7677
await asyncio.gather(task1, task2)

0 commit comments

Comments
 (0)