Skip to content

Commit 5200052

Browse files
committed
status: only count "running"/"pending" scenarios as "active"
1 parent 4111810 commit 5200052

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

src/warnet/status.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def status():
3131
table.add_row("", "", "")
3232

3333
# Add scenarios to the table
34+
active = 0
3435
if scenarios:
3536
for scenario in scenarios:
3637
table.add_row("Scenario", scenario["name"], scenario["status"])
38+
if scenario["status"] == "running" or scenario["status"] == "pending":
39+
active += 1
3740
else:
3841
table.add_row("Scenario", "No active scenarios", "")
3942

@@ -52,7 +55,7 @@ def status():
5255
# Print summary
5356
summary = Text()
5457
summary.append(f"\nTotal Tanks: {len(tanks)}", style="bold cyan")
55-
summary.append(f" | Active Scenarios: {len(scenarios)}", style="bold green")
58+
summary.append(f" | Active Scenarios: {active}", style="bold green")
5659
console.print(summary)
5760
_connected(end="\r")
5861

test/data/scenario_buggy_failure.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
4+
# The base class exists inside the commander container
5+
try:
6+
from commander import Commander
7+
except Exception:
8+
from resources.scenarios.commander import Commander
9+
10+
class Failure(Commander):
11+
def set_test_params(self):
12+
self.num_nodes = 1
13+
14+
def add_options(self, parser):
15+
parser.description = "This test will fail and exit with code 222"
16+
parser.usage = "warnet run /path/to/scenario_buggy_failure.py"
17+
18+
def run_test(self):
19+
raise Exception("Failed execution!")
20+
21+
22+
if __name__ == "__main__":
23+
Failure().main()

test/data/scenario_connect_dag.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
from commander import Commander
88

99

10-
def cli_help():
11-
return "Connect a complete DAG from a set of unconnected nodes"
12-
13-
1410
@unique
1511
class ConnectionType(Enum):
1612
IP = auto()
@@ -22,6 +18,10 @@ def set_test_params(self):
2218
# This is just a minimum
2319
self.num_nodes = 10
2420

21+
def add_options(self, parser):
22+
parser.description = "Connect a complete DAG from a set of unconnected nodes"
23+
parser.usage = "warnet run /path/to/scenario_connect_dag.py"
24+
2525
def run_test(self):
2626
# All permutations of a directed acyclic graph with zero, one, or two inputs/outputs
2727
#

test/data/scenario_p2p_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
from test_framework.p2p import P2PInterface
1313

1414

15-
def cli_help():
16-
return "Run P2P GETDATA test"
17-
18-
1915
class P2PStoreBlock(P2PInterface):
2016
def __init__(self):
2117
super().__init__()
@@ -30,6 +26,10 @@ class GetdataTest(Commander):
3026
def set_test_params(self):
3127
self.num_nodes = 1
3228

29+
def add_options(self, parser):
30+
parser.description = "Run P2P GETDATA test"
31+
parser.usage = "warnet run /path/to/scenario_p2p_interface.py"
32+
3333
def run_test(self):
3434
self.log.info("Adding the p2p connection")
3535

test/scenarios_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def run_test(self):
2121
self.run_and_check_miner_scenario_from_file()
2222
self.run_and_check_scenario_from_file()
2323
self.check_regtest_recon()
24+
self.check_active_count()
2425
finally:
2526
self.cleanup()
2627

@@ -76,6 +77,8 @@ def run_and_check_miner_scenario_from_file(self):
7677
start = int(self.warnet("bitcoin rpc tank-0000 getblockcount"))
7778
self.wait_for_predicate(lambda: self.scenario_running("commander-minerstd"))
7879
self.wait_for_predicate(lambda: self.check_blocks(2, start=start))
80+
table = self.warnet("status")
81+
assert "Active Scenarios: 1" in table
7982
self.stop_scenario()
8083

8184
def run_and_check_scenario_from_file(self):
@@ -90,6 +93,22 @@ def check_regtest_recon(self):
9093
self.warnet(f"run {scenario_file}")
9194
self.wait_for_predicate(self.check_scenario_clean_exit)
9295

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+
if len([s for s in deployed if s["status"] == "failed"]) != 1:
106+
return False
107+
return True
108+
self.wait_for_predicate(two_pass_one_fail)
109+
table = self.warnet("status")
110+
assert "Active Scenarios: 0" in table
111+
93112

94113
if __name__ == "__main__":
95114
test = ScenariosTest()

0 commit comments

Comments
 (0)