Skip to content

Commit c9a13ff

Browse files
committed
More tests.
1 parent 1baab0f commit c9a13ff

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

async_substrate_interface/substrate_addons.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ def _retry(self, method, *args, **kwargs):
168168
method_ = self._original_methods[method]
169169
try:
170170
return method_(*args, **kwargs)
171-
except (MaxRetriesExceeded, ConnectionError, EOFError, ConnectionClosed) as e:
171+
except (
172+
MaxRetriesExceeded,
173+
ConnectionError,
174+
EOFError,
175+
ConnectionClosed,
176+
TimeoutError,
177+
) as e:
172178
try:
173179
self._reinstantiate_substrate(e)
174180
return method_(*args, **kwargs)

tests/test_substrate_addons.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import time
66

77
from async_substrate_interface.substrate_addons import RetrySyncSubstrate
8+
from async_substrate_interface.errors import MaxRetriesExceeded
89
from tests.conftest import start_docker_container
910

11+
LATENT_LITE_ENTRYPOINT = "wss://lite.sub.latent.to:443"
12+
1013

1114
@pytest.fixture(scope="function")
1215
def docker_containers():
@@ -16,22 +19,51 @@ def docker_containers():
1619

1720
finally:
1821
for process in processes:
19-
subprocess.run(["docker", "kill", process[1]])
20-
process[0].kill()
22+
subprocess.run(["docker", "kill", process.name])
23+
process.process.kill()
24+
25+
26+
@pytest.fixture(scope="function")
27+
def single_local_chain():
28+
process = start_docker_container(9945, 9945)
29+
try:
30+
yield process
31+
finally:
32+
print("TRIGGERED KILL")
33+
subprocess.run(["docker", "kill", process.name])
34+
process.process.kill()
2135

2236

23-
def test_retry_sync_substrate(docker_containers):
37+
def test_retry_sync_substrate(single_local_chain):
2438
time.sleep(10)
2539
with RetrySyncSubstrate(
26-
docker_containers[0].uri, fallback_chains=[docker_containers[1].uri]
40+
single_local_chain.uri, fallback_chains=[LATENT_LITE_ENTRYPOINT]
2741
) as substrate:
2842
for i in range(10):
2943
assert substrate.get_chain_head().startswith("0x")
3044
if i == 8:
31-
subprocess.run(["docker", "stop", docker_containers[0].name])
32-
time.sleep(10)
45+
subprocess.run(["docker", "stop", single_local_chain.name])
3346
if i > 8:
47+
assert substrate.chain_endpoint == LATENT_LITE_ENTRYPOINT
48+
time.sleep(2)
49+
50+
51+
def test_retry_sync_substrate_max_retries(docker_containers):
52+
time.sleep(10)
53+
with RetrySyncSubstrate(
54+
docker_containers[0].uri, fallback_chains=[docker_containers[1].uri]
55+
) as substrate:
56+
for i in range(5):
57+
print("EYE EQUALS", i)
58+
assert substrate.get_chain_head().startswith("0x")
59+
if i == 2:
60+
subprocess.run(["docker", "pause", docker_containers[0].name])
61+
if i == 3:
3462
assert substrate.chain_endpoint == docker_containers[1].uri
63+
if i == 4:
64+
subprocess.run(["docker", "pause", docker_containers[1].name])
65+
with pytest.raises(MaxRetriesExceeded):
66+
substrate.get_chain_head().startswith("0x")
3567
time.sleep(2)
3668

3769

0 commit comments

Comments
 (0)