Skip to content

Commit 9afcbe3

Browse files
Add a restart test
1 parent 83aa120 commit 9afcbe3

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ edition = "2021"
55

66
[dependencies]
77
rustreexo = { git = "https://www.github.com/mit-dci/rustreexo" }
8-
# btcd-rpc = { git = "https://github.com/Davidson-Souza/rust-btcd-rpc", features = ["utreexod"], branch = "use-reqwest"}
9-
btcd-rpc = { path = "../utreexod-cli/client/", features = ["utreexod"] }
10-
clap = {version = "4.0.29", features = ["derive"]}
8+
btcd-rpc = { git = "https://github.com/Davidson-Souza/rust-btcd-rpc", features = ["utreexod"], branch = "use-reqwest"}
9+
clap = { version = "4.0.29", features = ["derive"] }
1110
sha2 = "^0.10.6"
1211
async-std = "1.12.0"
1312
log = "0.4"

tests/example_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from test_framework.electrum_client import ElectrumClient
99
from test_framework.mock_rpc import MockUtreexod
1010

11-
# Tests should be a child class from TestFramework
12-
1311

1412
class ExampleTest(TestFramework):
13+
""" Tests should be a child class from TestFramework """
14+
1515
# All tests should override the run_test method
1616
def run_test(self):
1717
# This creates a dummy rpc listening on port 8080
@@ -28,8 +28,10 @@ def run_test(self):
2828
print(electrum.get_version())
2929

3030
# .... cleanup ....
31-
os.rmdir("./data")
32-
# Stop any rpc server that is running
33-
self.stop_rpc()
31+
3432
# Stop the node that is running
3533
self.stop_node(0)
34+
35+
36+
if __name__ == '__main__':
37+
ExampleTest().main()
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ def run_test(self):
1111
Tests if we don't corrupt our data dir between restarts. This would have caught,
1212
the error fixed in #9
1313
"""
14-
print("Running restart test")
1514
base_testdir = "data/TestRestart/"
1615
self.run_node(base_testdir + "1/")
17-
time.sleep(10)
16+
time.sleep(5)
1817
self.stop_node(0)
1918
self.run_node(base_testdir + "2/")
20-
time.sleep(10)
19+
time.sleep(5)
2120
self.stop_node(0)
2221
assert (filecmp.dircmp(base_testdir + "2/", base_testdir + "1/"))
23-
print("restart test passed!")

tests/run_tests.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import subprocess
3+
import time
4+
from tqdm import tqdm
5+
6+
BASE_DIR = "/tmp/data"
7+
8+
tests = ["example_test", "restart"]
9+
10+
11+
def main():
12+
print("Creating work dir")
13+
data_dir = BASE_DIR + f"run-{time.time()}/"
14+
if not os.path.isdir(data_dir):
15+
os.makedirs(data_dir)
16+
print("Running tests")
17+
for test_name in tqdm(tests):
18+
test_dir = "./tests/" + test_name
19+
log_dir = data_dir + test_name.replace(".py", ".log")
20+
log_file = open(log_dir, "wt")
21+
test = subprocess.Popen(["python", test_dir + ".py"],
22+
stdout=log_file, stderr=log_file)
23+
test.wait()
24+
if test.returncode != 0:
25+
print(f"Test {test_name} not passed")
26+
else:
27+
print(f"Test {test_name} passed")
28+
29+
30+
if __name__ == '__main__':
31+
main()

tests/test_framework/test_framework.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ def run_rpc(self):
2323
self.rpc.daemon = True
2424
self.rpc.start()
2525

26-
def stop_rpc(self):
27-
self.rpc._stop()
28-
2926
def stop_node(self, idx: int):
3027
self.nodes[idx].send_signal(15)
28+
self.nodes[idx].wait()
3129

3230
# Should be overrided by individual tests
31+
3332
def run_test(self):
3433
raise NotImplemented
34+
35+
def main(self):
36+
self.run_test()

0 commit comments

Comments
 (0)