Skip to content

Commit

Permalink
Add a restart test
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidson-Souza committed Feb 13, 2023
1 parent 83aa120 commit 9afcbe3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ edition = "2021"

[dependencies]
rustreexo = { git = "https://www.github.com/mit-dci/rustreexo" }
# btcd-rpc = { git = "https://github.com/Davidson-Souza/rust-btcd-rpc", features = ["utreexod"], branch = "use-reqwest"}
btcd-rpc = { path = "../utreexod-cli/client/", features = ["utreexod"] }
clap = {version = "4.0.29", features = ["derive"]}
btcd-rpc = { git = "https://github.com/Davidson-Souza/rust-btcd-rpc", features = ["utreexod"], branch = "use-reqwest"}
clap = { version = "4.0.29", features = ["derive"] }
sha2 = "^0.10.6"
async-std = "1.12.0"
log = "0.4"
Expand Down
12 changes: 7 additions & 5 deletions tests/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from test_framework.electrum_client import ElectrumClient
from test_framework.mock_rpc import MockUtreexod

# Tests should be a child class from TestFramework


class ExampleTest(TestFramework):
""" Tests should be a child class from TestFramework """

# All tests should override the run_test method
def run_test(self):
# This creates a dummy rpc listening on port 8080
Expand All @@ -28,8 +28,10 @@ def run_test(self):
print(electrum.get_version())

# .... cleanup ....
os.rmdir("./data")
# Stop any rpc server that is running
self.stop_rpc()

# Stop the node that is running
self.stop_node(0)


if __name__ == '__main__':
ExampleTest().main()
6 changes: 2 additions & 4 deletions tests/basic/restart.py → tests/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ def run_test(self):
Tests if we don't corrupt our data dir between restarts. This would have caught,
the error fixed in #9
"""
print("Running restart test")
base_testdir = "data/TestRestart/"
self.run_node(base_testdir + "1/")
time.sleep(10)
time.sleep(5)
self.stop_node(0)
self.run_node(base_testdir + "2/")
time.sleep(10)
time.sleep(5)
self.stop_node(0)
assert (filecmp.dircmp(base_testdir + "2/", base_testdir + "1/"))
print("restart test passed!")
31 changes: 31 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import subprocess
import time
from tqdm import tqdm

BASE_DIR = "/tmp/data"

tests = ["example_test", "restart"]


def main():
print("Creating work dir")
data_dir = BASE_DIR + f"run-{time.time()}/"
if not os.path.isdir(data_dir):
os.makedirs(data_dir)
print("Running tests")
for test_name in tqdm(tests):
test_dir = "./tests/" + test_name
log_dir = data_dir + test_name.replace(".py", ".log")
log_file = open(log_dir, "wt")
test = subprocess.Popen(["python", test_dir + ".py"],
stdout=log_file, stderr=log_file)
test.wait()
if test.returncode != 0:
print(f"Test {test_name} not passed")
else:
print(f"Test {test_name} passed")


if __name__ == '__main__':
main()
8 changes: 5 additions & 3 deletions tests/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def run_rpc(self):
self.rpc.daemon = True
self.rpc.start()

def stop_rpc(self):
self.rpc._stop()

def stop_node(self, idx: int):
self.nodes[idx].send_signal(15)
self.nodes[idx].wait()

# Should be overrided by individual tests

def run_test(self):
raise NotImplemented

def main(self):
self.run_test()

0 comments on commit 9afcbe3

Please sign in to comment.