MCPcopy Create free account
hub / github.com/ElementsProject/elements / run_test

Method run_test

test/functional/interface_http.py:21–105  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

19 self.setup_nodes()
20
21 def run_test(self):
22
23 #################################################
24 # lowlevel check for http persistent connection #
25 #################################################
26 url = urllib.parse.urlparse(self.nodes[0].url)
27 authpair = f'{url.username}:{url.password}'
28 headers = {"Authorization": f"Basic {str_to_b64str(authpair)}"}
29
30 conn = http.client.HTTPConnection(url.hostname, url.port)
31 conn.connect()
32 conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
33 out1 = conn.getresponse().read()
34 assert b'"error":null' in out1
35 assert conn.sock is not None #according to http/1.1 connection must still be open!
36
37 #send 2nd request without closing connection
38 conn.request('POST', '/', '{"method": "getchaintips"}', headers)
39 out1 = conn.getresponse().read()
40 assert b'"error":null' in out1 #must also response with a correct json-rpc message
41 assert conn.sock is not None #according to http/1.1 connection must still be open!
42 conn.close()
43
44 #same should be if we add keep-alive because this should be the std. behaviour
45 headers = {"Authorization": f"Basic {str_to_b64str(authpair)}", "Connection": "keep-alive"}
46
47 conn = http.client.HTTPConnection(url.hostname, url.port)
48 conn.connect()
49 conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
50 out1 = conn.getresponse().read()
51 assert b'"error":null' in out1
52 assert conn.sock is not None #according to http/1.1 connection must still be open!
53
54 #send 2nd request without closing connection
55 conn.request('POST', '/', '{"method": "getchaintips"}', headers)
56 out1 = conn.getresponse().read()
57 assert b'"error":null' in out1 #must also response with a correct json-rpc message
58 assert conn.sock is not None #according to http/1.1 connection must still be open!
59 conn.close()
60
61 #now do the same with "Connection: close"
62 headers = {"Authorization": f"Basic {str_to_b64str(authpair)}", "Connection":"close"}
63
64 conn = http.client.HTTPConnection(url.hostname, url.port)
65 conn.connect()
66 conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
67 out1 = conn.getresponse().read()
68 assert b'"error":null' in out1
69 assert conn.sock is None #now the connection must be closed after the response
70
71 #node1 (2nd node) is running with disabled keep-alive option
72 urlNode1 = urllib.parse.urlparse(self.nodes[1].url)
73 authpair = f'{urlNode1.username}:{urlNode1.password}'
74 headers = {"Authorization": f"Basic {str_to_b64str(authpair)}"}
75
76 conn = http.client.HTTPConnection(urlNode1.hostname, urlNode1.port)
77 conn.connect()
78 conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)

Callers

nothing calls this directly

Calls 6

str_to_b64strFunction · 0.90
assert_equalFunction · 0.90
connectMethod · 0.80
requestMethod · 0.80
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected