2
2
3
3
import os
4
4
from pathlib import Path
5
-
5
+ from warnet .cli .scenarios import _available as scenarios_available
6
+ from warnet .cli .scenarios import _active as scenarios_active
7
+ from warnet .cli .k8s import delete_pod
6
8
from test_base import TestBase
7
9
8
10
@@ -13,7 +15,6 @@ def __init__(self):
13
15
14
16
def run_test (self ):
15
17
try :
16
- self .start_server ()
17
18
self .setup_network ()
18
19
self .test_scenarios ()
19
20
finally :
@@ -23,85 +24,71 @@ def setup_network(self):
23
24
self .log .info ("Setting up network" )
24
25
self .log .info (self .warcli (f"network start { self .graph_file_path } " ))
25
26
self .wait_for_all_tanks_status (target = "running" )
27
+ self .wait_for_all_edges ()
26
28
27
29
def test_scenarios (self ):
28
30
self .check_available_scenarios ()
29
- self .run_and_check_miner_scenario ("miner_std" )
30
- self .run_and_check_miner_scenario_from_file ("src/warnet/scenarios/miner_std.py" )
31
- self .run_and_check_scenario_from_file ("test/data/scenario_p2p_interface.py" )
31
+ self .run_and_check_miner_scenario ()
32
+ self .run_and_check_miner_scenario_from_file ()
33
+ self .run_and_check_scenario_from_file ()
32
34
33
35
def check_available_scenarios (self ):
34
36
self .log .info ("Checking available scenarios" )
35
37
# Use rpc instead of warcli so we get raw JSON object
36
- scenarios = self . rpc ( " scenarios_available" )
38
+ scenarios = scenarios_available ( )
37
39
assert len (scenarios ) == 4 , f"Expected 4 available scenarios, got { len (scenarios )} "
38
40
self .log .info (f"Found { len (scenarios )} available scenarios" )
39
41
40
42
def scenario_running (self , scenario_name : str ):
41
43
"""Check that we are only running a single scenario of the correct name"""
42
- active = self . rpc ( "scenarios_list_running" )
43
- running = scenario_name in active [ 0 ][ "cmd" ]
44
- return running and len ( active ) == 1
44
+ active = scenarios_active ( )
45
+ assert len ( active ) == 1
46
+ return scenario_name in active [ 0 ][ "commander" ]
45
47
46
- def run_and_check_scenario_from_file (self , scenario_file ):
47
- scenario_name = self . get_scenario_name_from_path ( scenario_file )
48
+ def run_and_check_scenario_from_file (self ):
49
+ scenario_file = "test/data/scenario_p2p_interface.py"
48
50
49
51
def check_scenario_clean_exit ():
50
- running = self .rpc ("scenarios_list_running" )
51
- scenarios = [s for s in running if s ["cmd" ].strip () == scenario_name ]
52
- if not scenarios :
53
- return False
54
- scenario = scenarios [0 ]
55
- if scenario ["active" ]:
56
- return False
57
- if scenario ["return_code" ] != 0 :
58
- raise Exception (
59
- f"Scenario { scenario_name } failed with return code { scenario ['return_code' ]} "
60
- )
61
- return True
62
-
63
- self .log .info (f"Running scenario: { scenario_name } " )
52
+ active = scenarios_active ()
53
+ assert len (active ) == 1
54
+ return active [0 ]["status" ] == "succeeded"
55
+
56
+ self .log .info (f"Running scenario from: { scenario_file } " )
64
57
self .warcli (f"scenarios run-file { scenario_file } " )
65
58
self .wait_for_predicate (lambda : check_scenario_clean_exit ())
66
59
67
- def run_and_check_miner_scenario (self , scenario_name ):
68
- self .log .info (f"Running scenario: { scenario_name } " )
69
- self .warcli (f"scenarios run { scenario_name } --allnodes --interval=1" )
70
- self .wait_for_predicate (lambda : self .scenario_running (scenario_name ))
60
+ def run_and_check_miner_scenario (self ):
61
+ sc = "miner_std"
62
+ self .log .info (f"Running scenario { sc } " )
63
+ self .warcli (f"scenarios run { sc } --allnodes --interval=1" )
64
+ self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
71
65
self .wait_for_predicate (lambda : self .check_blocks (30 ))
72
66
self .stop_scenario ()
73
67
74
- def run_and_check_miner_scenario_from_file (self , scenario_file ):
68
+ def run_and_check_miner_scenario_from_file (self ):
69
+ scenario_file = "src/warnet/scenarios/miner_std.py"
75
70
self .log .info (f"Running scenario from file: { scenario_file } " )
76
71
self .warcli (f"scenarios run-file { scenario_file } --allnodes --interval=1" )
77
72
start = int (self .warcli ("bitcoin rpc 0 getblockcount" ))
78
- scenario_name = self .get_scenario_name_from_path (scenario_file )
79
- self .wait_for_predicate (lambda : self .scenario_running (scenario_name ))
73
+ self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
80
74
self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
81
75
self .stop_scenario ()
82
76
83
- def get_scenario_name_from_path (self , scenario_file ):
84
- return os .path .splitext (os .path .basename (scenario_file ))[0 ]
85
-
86
77
def check_blocks (self , target_blocks , start : int = 0 ):
87
- running = self .rpc ("scenarios_list_running" )
88
- assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
89
- assert running [0 ]["active" ], "Scenario should be active"
90
-
91
78
count = int (self .warcli ("bitcoin rpc 0 getblockcount" ))
92
79
self .log .debug (f"Current block count: { count } , target: { start + target_blocks } " )
93
80
return count >= start + target_blocks
94
81
95
82
def stop_scenario (self ):
96
83
self .log .info ("Stopping running scenario" )
97
- running = self . rpc ( "scenarios_list_running" )
84
+ running = scenarios_active ( )
98
85
assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
99
- assert running [0 ]["active" ] , "Scenario should be active "
100
- self . warcli ( f"scenarios stop { running [0 ]['pid' ] } " , False )
86
+ assert running [0 ]["status" ] == "running" , "Scenario should be running "
87
+ delete_pod ( running [0 ]["commander" ] )
101
88
self .wait_for_predicate (self .check_scenario_stopped )
102
89
103
90
def check_scenario_stopped (self ):
104
- running = self . rpc ( "scenarios_list_running" )
91
+ running = scenarios_active ( )
105
92
self .log .debug (f"Checking if scenario stopped. Running scenarios: { len (running )} " )
106
93
return len (running ) == 0
107
94
0 commit comments