-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [tests] separate test framework into separate module * [tests] update integration test README
- Loading branch information
Showing
4 changed files
with
85 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,5 @@ script: | |
- go get -v ./... | ||
- go test ./... | ||
- go build | ||
- test/test_lit.py | ||
- test/test_basic.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
# Lit integration tests | ||
|
||
run tests with ./test_lit.py | ||
This directory contains lit integration tests, which start lit and bitcoind/litecoind nodes and test functionality. | ||
|
||
Requires: | ||
### Directory Structure | ||
|
||
- `lit_test_framework.py` is the test framework. Individual test cases should import this and subclass the LitTest class | ||
- `litnode.py` contains a class representing a lit node. This can be used to start/stop the node and communicate with it over the websocket RPC. | ||
- `bcnode.py` contains a class representing a bitcoind node or litecoin node. These can be used to start/stop the bitcoin/litecoin nodes and communicate with them over RPC. | ||
- `test_*.py` individual tests cases. | ||
|
||
### Dependencies | ||
|
||
- websocket-client (`pip install websocket-client`) | ||
- requests (`pip install requests`) | ||
- bitcoind and litecoind on the path | ||
|
||
### Running tests | ||
|
||
Run tests with `./test_[testname].py` | ||
|
||
### Adding tests | ||
|
||
New tests should be named `tests_[description].py`. They should import the `LitTest` class from `lit_test_framework.py`. The test should subclass the `LitTest` class and override the `run_test()` method to include its own test logic. See `test_basic.py` for an example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2017 The lit developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. | ||
"""Test lit""" | ||
import subprocess | ||
import sys | ||
import tempfile | ||
import traceback | ||
|
||
class LitTest(): | ||
def __init__(self): | ||
self.litnodes = [] | ||
self.bcnodes = [] | ||
self.tmpdir = tempfile.mkdtemp(prefix="test") | ||
print("Using tmp dir %s" % self.tmpdir) | ||
|
||
def main(self): | ||
rc = 0 | ||
try: | ||
self.run_test() | ||
print("Test succeeds!") | ||
except: | ||
# Test asserted. Return 1 | ||
print("Unexpected error:", sys.exc_info()[0]) | ||
traceback.print_exc(file=sys.stdout) | ||
rc = 1 | ||
finally: | ||
self.cleanup() | ||
|
||
return rc | ||
|
||
def run_test(self): | ||
"""Test Logic. This method should be overridden by subclasses""" | ||
raise NotImplementedError | ||
|
||
def cleanup(self): | ||
# Stop bitcoind and lit nodes | ||
for bcnode in self.bcnodes: | ||
bcnode.stop() | ||
try: | ||
bcnode.process.wait(2) | ||
except subprocess.TimeoutExpired: | ||
bcnode.process.kill() | ||
for litnode in self.litnodes: | ||
litnode.Stop() | ||
try: | ||
litnode.process.wait(2) | ||
except subprocess.TimeoutExpired: | ||
litnode.process.kill() | ||
|
||
if __name__ == "__main__": | ||
exit(LitTest().main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters