Skip to content

Commit 1dd8ee7

Browse files
jonasschnelligmaxwell
authored andcommitted
improve tests for #5655
1 parent 56c1093 commit 1dd8ee7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

qa/rpc-tests/httpbasics.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class HTTPBasicsTest (BitcoinTestFramework):
2424
def setup_nodes(self):
25-
return start_nodes(4, self.options.tmpdir, extra_args=[['-rpckeepalive']]*4)
25+
return start_nodes(4, self.options.tmpdir, extra_args=[['-rpckeepalive=1'], ['-rpckeepalive=0'], [], []])
2626

2727
def run_test(self):
2828

@@ -74,6 +74,29 @@ def run_test(self):
7474
assert_equal('"error":null' in out1, True)
7575
assert_equal(conn.sock!=None, False) #now the connection must be closed after the response
7676

77+
#node1 (2nd node) is running with disabled keep-alive option
78+
urlNode1 = urlparse.urlparse(self.nodes[1].url)
79+
authpair = urlNode1.username + ':' + urlNode1.password
80+
headers = {"Authorization": "Basic " + base64.b64encode(authpair)}
81+
82+
conn = httplib.HTTPConnection(urlNode1.hostname, urlNode1.port)
83+
conn.connect()
84+
conn.request('GET', '/', '{"method": "getbestblockhash"}', headers)
85+
out1 = conn.getresponse().read();
86+
assert_equal('"error":null' in out1, True)
87+
assert_equal(conn.sock!=None, False) #connection must be closed because keep-alive was set to false
88+
89+
#node2 (third node) is running with standard keep-alive parameters which means keep-alive is off
90+
urlNode2 = urlparse.urlparse(self.nodes[2].url)
91+
authpair = urlNode2.username + ':' + urlNode2.password
92+
headers = {"Authorization": "Basic " + base64.b64encode(authpair)}
93+
94+
conn = httplib.HTTPConnection(urlNode2.hostname, urlNode2.port)
95+
conn.connect()
96+
conn.request('GET', '/', '{"method": "getbestblockhash"}', headers)
97+
out1 = conn.getresponse().read();
98+
assert_equal('"error":null' in out1, True)
99+
assert_equal(conn.sock!=None, False) #connection must be closed because bitcoind should use keep-alive by default
77100

78101
if __name__ == '__main__':
79102
HTTPBasicsTest ().main ()

0 commit comments

Comments
 (0)