|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | from libterraform import TerraformCommand, TerraformPool |
| 8 | +import libterraform.pool as pool_module |
8 | 9 | from libterraform.cli import CommandResult |
9 | 10 | from libterraform.exceptions import TerraformCommandError |
10 | 11 | from libterraform.pool import PoolCommand |
@@ -69,6 +70,47 @@ def test_pool_shutdown_rejects_new_work(): |
69 | 70 | pool.run("version") |
70 | 71 |
|
71 | 72 |
|
| 73 | +def test_pool_defaults_to_spawn_context(monkeypatch): |
| 74 | + calls = [] |
| 75 | + created = {} |
| 76 | + |
| 77 | + class FakeManager: |
| 78 | + def dict(self): |
| 79 | + return {} |
| 80 | + |
| 81 | + def shutdown(self): |
| 82 | + pass |
| 83 | + |
| 84 | + class FakeContext: |
| 85 | + def Manager(self): |
| 86 | + return FakeManager() |
| 87 | + |
| 88 | + class FakeExecutor: |
| 89 | + def __init__(self, **kwargs): |
| 90 | + created.update(kwargs) |
| 91 | + |
| 92 | + def shutdown(self, wait=True, *, cancel_futures=False): |
| 93 | + created["shutdown"] = (wait, cancel_futures) |
| 94 | + |
| 95 | + fake_context = FakeContext() |
| 96 | + |
| 97 | + def fake_get_context(method): |
| 98 | + calls.append(method) |
| 99 | + return fake_context |
| 100 | + |
| 101 | + monkeypatch.setattr(pool_module.multiprocessing, "get_context", fake_get_context) |
| 102 | + monkeypatch.setattr(pool_module, "ProcessPoolExecutor", FakeExecutor) |
| 103 | + |
| 104 | + pool = TerraformPool(max_workers=1) |
| 105 | + pool.shutdown() |
| 106 | + |
| 107 | + assert calls == ["spawn"] |
| 108 | + assert created["max_workers"] == 1 |
| 109 | + assert created["mp_context"] is fake_context |
| 110 | + assert created["initargs"][0] == {} |
| 111 | + assert created["shutdown"] == (True, False) |
| 112 | + |
| 113 | + |
72 | 114 | def test_pool_command_proxy_exposes_public_sync_methods(): |
73 | 115 | from libterraform.cli import _STREAM_METHODS |
74 | 116 |
|
|
0 commit comments