|
9 | 9 |
|
10 | 10 |
|
11 | 11 | @pytest.fixture(scope="function")
|
12 |
| -def start_containers(): |
13 |
| - # Store our subprocesses globally |
| 12 | +def docker_containers(): |
14 | 13 | processes = (start_docker_container(9945, 9945), start_docker_container(9946, 9946))
|
15 |
| - yield processes |
| 14 | + try: |
| 15 | + yield processes |
16 | 16 |
|
17 |
| - # To stop the instances, you can iterate over the processes and kill them: |
18 |
| - for process in processes: |
19 |
| - subprocess.run(["docker", "kill", process[1]]) |
20 |
| - process[0].kill() |
| 17 | + finally: |
| 18 | + for process in processes: |
| 19 | + subprocess.run(["docker", "kill", process[1]]) |
| 20 | + process[0].kill() |
21 | 21 |
|
22 | 22 |
|
23 |
| -def test_retry_sync_substrate(start_containers): |
24 |
| - container1, container2 = start_containers |
| 23 | +def test_retry_sync_substrate(docker_containers): |
25 | 24 | time.sleep(10)
|
26 | 25 | with RetrySyncSubstrate(
|
27 |
| - "ws://127.0.0.1:9945", fallback_chains=["ws://127.0.0.1:9946"] |
| 26 | + docker_containers[0].uri, fallback_chains=[docker_containers[1].uri] |
28 | 27 | ) as substrate:
|
29 | 28 | for i in range(10):
|
30 | 29 | assert substrate.get_chain_head().startswith("0x")
|
31 | 30 | if i == 8:
|
32 |
| - subprocess.run(["docker", "kill", container1[1]]) |
| 31 | + subprocess.run(["docker", "stop", docker_containers[0].name]) |
33 | 32 | time.sleep(10)
|
34 | 33 | if i > 8:
|
35 |
| - assert substrate.chain_endpoint == "ws://127.0.0.1:9946" |
| 34 | + assert substrate.chain_endpoint == docker_containers[1].uri |
36 | 35 | time.sleep(2)
|
| 36 | + |
| 37 | + |
| 38 | +def test_retry_sync_substrate_offline(): |
| 39 | + with pytest.raises(ConnectionError): |
| 40 | + RetrySyncSubstrate( |
| 41 | + "ws://127.0.0.1:9945", fallback_chains=["ws://127.0.0.1:9946"] |
| 42 | + ) |
0 commit comments