8
8
from test_framework .authproxy import JSONRPCException
9
9
from test_framework .test_framework import BitcoinTestFramework
10
10
from test_framework .util import assert_equal , assert_greater_than_or_equal
11
+ from threading import Thread
12
+ import subprocess
13
+
11
14
12
15
def expect_http_status (expected_http_status , expected_rpc_code ,
13
16
fcn , * args ):
@@ -18,6 +21,16 @@ def expect_http_status(expected_http_status, expected_rpc_code,
18
21
assert_equal (exc .error ["code" ], expected_rpc_code )
19
22
assert_equal (exc .http_status , expected_http_status )
20
23
24
+
25
+ def test_work_queue_getblock (node , got_exceeded_error ):
26
+ while not got_exceeded_error :
27
+ try :
28
+ node .cli ('getrpcinfo' ).send_cli ()
29
+ except subprocess .CalledProcessError as e :
30
+ assert_equal (e .output , 'error: Server response: Work queue depth exceeded\n ' )
31
+ got_exceeded_error .append (True )
32
+
33
+
21
34
class RPCInterfaceTest (BitcoinTestFramework ):
22
35
def set_test_params (self ):
23
36
self .num_nodes = 1
@@ -67,10 +80,23 @@ def test_http_status_codes(self):
67
80
expect_http_status (404 , - 32601 , self .nodes [0 ].invalidmethod )
68
81
expect_http_status (500 , - 8 , self .nodes [0 ].getblockhash , 42 )
69
82
83
+ def test_work_queue_exceeded (self ):
84
+ self .log .info ("Testing work queue exceeded..." )
85
+ self .restart_node (0 , ['-rpcworkqueue=1' , '-rpcthreads=1' ])
86
+ got_exceeded_error = []
87
+ threads = []
88
+ for _ in range (3 ):
89
+ t = Thread (target = test_work_queue_getblock , args = (self .nodes [0 ], got_exceeded_error ))
90
+ t .start ()
91
+ threads .append (t )
92
+ for t in threads :
93
+ t .join ()
94
+
70
95
def run_test (self ):
71
96
self .test_getrpcinfo ()
72
97
self .test_batch_request ()
73
98
self .test_http_status_codes ()
99
+ self .test_work_queue_exceeded ()
74
100
75
101
76
102
if __name__ == '__main__' :
0 commit comments