Skip to content

Commit

Permalink
add functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryRuane committed Jul 21, 2020
1 parent b5a80fa commit c067589
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/functional/interface_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from test_framework.authproxy import JSONRPCException
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than_or_equal
from threading import Thread
import subprocess

def expect_http_status(expected_http_status, expected_rpc_code,
fcn, *args):
Expand All @@ -18,6 +20,20 @@ def expect_http_status(expected_http_status, expected_rpc_code,
assert_equal(exc.error["code"], expected_rpc_code)
assert_equal(exc.http_status, expected_http_status)

got_exceeded_error = False
def test_work_queue_getblock(node):
global got_exceeded_error
for _ in range(400):
if got_exceeded_error:
break
try:
node.cli('getrpcinfo').send_cli()
except subprocess.CalledProcessError as e:
if e.output != 'error: Server response: Work queue depth exceeded\n':
raise AssertionError("Unexpected cli error: :{}:".format(e.output))
got_exceeded_error = True
break

class RPCInterfaceTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
Expand Down Expand Up @@ -67,10 +83,26 @@ def test_http_status_codes(self):
expect_http_status(404, -32601, self.nodes[0].invalidmethod)
expect_http_status(500, -8, self.nodes[0].getblockhash, 42)

def test_work_queue_exceeded(self):
global got_exceeded_error
self.restart_node(0,['-rpcworkqueue=1'])
threads = []
for _ in range(5):
t = Thread(target=test_work_queue_getblock, args=(self.nodes[0], ))
t.start()
threads.append(t)
if got_exceeded_error:
break
for t in threads:
t.join()
# This likely just means more threads are needed.
assert(got_exceeded_error)

def run_test(self):
self.test_getrpcinfo()
self.test_batch_request()
self.test_http_status_codes()
self.test_work_queue_exceeded()


if __name__ == '__main__':
Expand Down

0 comments on commit c067589

Please sign in to comment.