7
7
8
8
from warnet .control import stop_scenario
9
9
from warnet .process import run_command
10
- from warnet .status import _get_active_scenarios as scenarios_active
10
+ from warnet .status import _get_deployed_scenarios as scenarios_deployed
11
11
12
12
13
13
class ScenariosTest (TestBase ):
@@ -18,7 +18,10 @@ def __init__(self):
18
18
def run_test (self ):
19
19
try :
20
20
self .setup_network ()
21
- self .test_scenarios ()
21
+ self .run_and_check_miner_scenario_from_file ()
22
+ self .run_and_check_scenario_from_file ()
23
+ self .check_regtest_recon ()
24
+ self .check_active_count ()
22
25
finally :
23
26
self .cleanup ()
24
27
@@ -28,49 +31,36 @@ def setup_network(self):
28
31
self .wait_for_all_tanks_status (target = "running" )
29
32
self .wait_for_all_edges ()
30
33
31
- def test_scenarios (self ):
32
- self .run_and_check_miner_scenario_from_file ()
33
- self .run_and_check_scenario_from_file ()
34
- self .check_regtest_recon ()
35
-
36
34
def scenario_running (self , scenario_name : str ):
37
35
"""Check that we are only running a single scenario of the correct name"""
38
- active = scenarios_active ()
39
- assert len (active ) == 1
40
- return scenario_name in active [0 ]["name" ]
41
-
42
- def run_and_check_scenario_from_file (self ):
43
- scenario_file = "test/data/scenario_p2p_interface.py"
44
- self .log .info (f"Running scenario from: { scenario_file } " )
45
- self .warnet (f"run { scenario_file } " )
46
- self .wait_for_predicate (self .check_scenario_clean_exit )
47
-
48
- def run_and_check_miner_scenario_from_file (self ):
49
- scenario_file = "resources/scenarios/miner_std.py"
50
- self .log .info (f"Running scenario from file: { scenario_file } " )
51
- self .warnet (f"run { scenario_file } --allnodes --interval=1" )
52
- start = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
53
- self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
54
- self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
55
- self .stop_scenario ()
36
+ deployed = scenarios_deployed ()
37
+ assert len (deployed ) == 1
38
+ return scenario_name in deployed [0 ]["name" ]
56
39
57
- def check_regtest_recon (self ):
58
- scenario_file = "resources/scenarios/reconnaissance.py"
59
- self .log .info (f"Running scenario from file: { scenario_file } " )
60
- self .warnet (f"run { scenario_file } " )
61
- self .wait_for_predicate (self .check_scenario_clean_exit )
40
+ def check_scenario_stopped (self ):
41
+ running = scenarios_deployed ()
42
+ self .log .debug (f"Checking if scenario stopped. Running scenarios: { len (running )} " )
43
+ return len (running ) == 0
62
44
63
45
def check_scenario_clean_exit (self ):
64
- active = scenarios_active ()
65
- return all (scenario ["status" ] == "succeeded" for scenario in active )
46
+ deployed = scenarios_deployed ()
47
+ return all (scenario ["status" ] == "succeeded" for scenario in deployed )
48
+
49
+ def stop_scenario (self ):
50
+ self .log .info ("Stopping running scenario" )
51
+ running = scenarios_deployed ()
52
+ assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
53
+ assert running [0 ]["status" ] == "running" , "Scenario should be running"
54
+ stop_scenario (running [0 ]["name" ])
55
+ self .wait_for_predicate (self .check_scenario_stopped )
66
56
67
57
def check_blocks (self , target_blocks , start : int = 0 ):
68
58
count = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
69
59
self .log .debug (f"Current block count: { count } , target: { start + target_blocks } " )
70
60
71
61
try :
72
- active = scenarios_active ()
73
- commander = active [0 ]["commander" ]
62
+ deployed = scenarios_deployed ()
63
+ commander = deployed [0 ]["commander" ]
74
64
command = f"kubectl logs { commander } "
75
65
print ("\n commander output:" )
76
66
print (run_command (command ))
@@ -80,18 +70,43 @@ def check_blocks(self, target_blocks, start: int = 0):
80
70
81
71
return count >= start + target_blocks
82
72
83
- def stop_scenario (self ):
84
- self .log .info ("Stopping running scenario" )
85
- running = scenarios_active ()
86
- assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
87
- assert running [0 ]["status" ] == "running" , "Scenario should be running"
88
- stop_scenario (running [0 ]["name" ])
89
- self .wait_for_predicate (self .check_scenario_stopped )
73
+ def run_and_check_miner_scenario_from_file (self ):
74
+ scenario_file = "resources/scenarios/miner_std.py"
75
+ self .log .info (f"Running scenario from file: { scenario_file } " )
76
+ self .warnet (f"run { scenario_file } --allnodes --interval=1" )
77
+ start = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
78
+ self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
79
+ self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
80
+ table = self .warnet ("status" )
81
+ assert "Active Scenarios: 1" in table
82
+ self .stop_scenario ()
90
83
91
- def check_scenario_stopped (self ):
92
- running = scenarios_active ()
93
- self .log .debug (f"Checking if scenario stopped. Running scenarios: { len (running )} " )
94
- return len (running ) == 0
84
+ def run_and_check_scenario_from_file (self ):
85
+ scenario_file = "test/data/scenario_p2p_interface.py"
86
+ self .log .info (f"Running scenario from: { scenario_file } " )
87
+ self .warnet (f"run { scenario_file } " )
88
+ self .wait_for_predicate (self .check_scenario_clean_exit )
89
+
90
+ def check_regtest_recon (self ):
91
+ scenario_file = "resources/scenarios/reconnaissance.py"
92
+ self .log .info (f"Running scenario from file: { scenario_file } " )
93
+ self .warnet (f"run { scenario_file } " )
94
+ self .wait_for_predicate (self .check_scenario_clean_exit )
95
+
96
+ def check_active_count (self ):
97
+ scenario_file = "test/data/scenario_buggy_failure.py"
98
+ self .log .info (f"Running scenario from: { scenario_file } " )
99
+ self .warnet (f"run { scenario_file } " )
100
+
101
+ def two_pass_one_fail ():
102
+ deployed = scenarios_deployed ()
103
+ if len ([s for s in deployed if s ["status" ] == "succeeded" ]) != 2 :
104
+ return False
105
+ return len ([s for s in deployed if s ["status" ] == "failed" ]) == 1
106
+
107
+ self .wait_for_predicate (two_pass_one_fail )
108
+ table = self .warnet ("status" )
109
+ assert "Active Scenarios: 0" in table
95
110
96
111
97
112
if __name__ == "__main__" :
0 commit comments