55import time
66
77from async_substrate_interface .substrate_addons import RetrySyncSubstrate
8+ from async_substrate_interface .errors import MaxRetriesExceeded
89from tests .conftest import start_docker_container
910
11+ LATENT_LITE_ENTRYPOINT = "wss://lite.sub.latent.to:443"
12+
1013
1114@pytest .fixture (scope = "function" )
1215def 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