5
5
import time
6
6
7
7
from async_substrate_interface .substrate_addons import RetrySyncSubstrate
8
+ from async_substrate_interface .errors import MaxRetriesExceeded
8
9
from tests .conftest import start_docker_container
9
10
11
+ LATENT_LITE_ENTRYPOINT = "wss://lite.sub.latent.to:443"
12
+
10
13
11
14
@pytest .fixture (scope = "function" )
12
15
def docker_containers ():
@@ -16,22 +19,51 @@ def docker_containers():
16
19
17
20
finally :
18
21
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 ()
21
35
22
36
23
- def test_retry_sync_substrate (docker_containers ):
37
+ def test_retry_sync_substrate (single_local_chain ):
24
38
time .sleep (10 )
25
39
with RetrySyncSubstrate (
26
- docker_containers [ 0 ] .uri , fallback_chains = [docker_containers [ 1 ]. uri ]
40
+ single_local_chain .uri , fallback_chains = [LATENT_LITE_ENTRYPOINT ]
27
41
) as substrate :
28
42
for i in range (10 ):
29
43
assert substrate .get_chain_head ().startswith ("0x" )
30
44
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 ])
33
46
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 :
34
62
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" )
35
67
time .sleep (2 )
36
68
37
69
0 commit comments