From 8463aaa63c5ac76421c4d2754ea9e17a31584c93 Mon Sep 17 00:00:00 2001
From: Russell Yanofsky <russ@yanofsky.org>
Date: Wed, 2 Nov 2016 09:46:55 -0400
Subject: [qa] Increase wallet-dump RPC timeout

Increase wallet-dump RPC timeout from 30 seconds to 1 minute. This avoids a
timeout error that seemed to happen regularly (around 50% of builds) on a
particular jenkins server during the first getnewaddress RPC call made by the
test.

The failing stack trace looked like:

    Unexpected exception caught during testing: timeout('timed out',)

    File ".../bitcoin/qa/rpc-tests/test_framework/test_framework.py", line 146, in main
      self.run_test()
    File ".../bitcoin/qa/rpc-tests/wallet-dump.py", line 73, in run_test
      addr = self.nodes[0].getnewaddress()
    File ".../bitcoin/qa/rpc-tests/test_framework/coverage.py", line 49, in __call__
      return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
    File ".../bitcoin/qa/rpc-tests/test_framework/authproxy.py", line 145, in __call__
      response = self._request('POST', self.__url.path, postdata.encode('utf-8'))
    File ".../bitcoin/qa/rpc-tests/test_framework/authproxy.py", line 121, in _request
      return self._get_response()
    File ".../bitcoin/qa/rpc-tests/test_framework/authproxy.py", line 160, in _get_response
      http_response = self.__conn.getresponse()
    File "/usr/lib/python3.4/http/client.py", line 1171, in getresponse
      response.begin()
    File "/usr/lib/python3.4/http/client.py", line 351, in begin
      version, status, reason = self._read_status()
    File "/usr/lib/python3.4/http/client.py", line 313, in _read_status
      line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    File "/usr/lib/python3.4/socket.py", line 374, in readinto
      return self._sock.recv_into(b)
---
 qa/rpc-tests/test_framework/util.py | 4 ++--
 qa/rpc-tests/wallet-dump.py         | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index c818af4bd7..c0c2b3a6ef 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -341,7 +341,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
 
     return proxy
 
-def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None):
+def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
     """
     Start multiple bitcoinds, return RPC connections to them
     """
@@ -350,7 +350,7 @@ def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None):
     rpcs = []
     try:
         for i in range(num_nodes):
-            rpcs.append(start_node(i, dirname, extra_args[i], rpchost, binary=binary[i]))
+            rpcs.append(start_node(i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i]))
     except: # If one node failed to start, stop the others
         stop_nodes(rpcs)
         raise
diff --git a/qa/rpc-tests/wallet-dump.py b/qa/rpc-tests/wallet-dump.py
index a37096a40c..c6dc2e3d10 100755
--- a/qa/rpc-tests/wallet-dump.py
+++ b/qa/rpc-tests/wallet-dump.py
@@ -61,7 +61,11 @@ class WalletDumpTest(BitcoinTestFramework):
         self.extra_args = [["-keypool=90"]]
 
     def setup_network(self, split=False):
-        self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
+        # Use 1 minute timeout because the initial getnewaddress RPC can take
+        # longer than the default 30 seconds due to an expensive
+        # CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
+        # the test often takes even longer.
+        self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60)
 
     def run_test (self):
         tmpdir = self.options.tmpdir
-- 
cgit v1.2.3


From e89614b6abf28d7fe201c3db44a0df6e4db6de03 Mon Sep 17 00:00:00 2001
From: Russell Yanofsky <russ@yanofsky.org>
Date: Wed, 2 Nov 2016 15:08:54 -0400
Subject: [qa] Add more helpful RPC timeout message

Replace previous timeout('timed out',) exception with more detailed error.
---
 qa/rpc-tests/test_framework/authproxy.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/qa/rpc-tests/test_framework/authproxy.py b/qa/rpc-tests/test_framework/authproxy.py
index fd7f32b5c6..dd183815da 100644
--- a/qa/rpc-tests/test_framework/authproxy.py
+++ b/qa/rpc-tests/test_framework/authproxy.py
@@ -42,6 +42,7 @@ import base64
 import decimal
 import json
 import logging
+import socket
 try:
     import urllib.parse as urlparse
 except ImportError:
@@ -161,7 +162,15 @@ class AuthServiceProxy(object):
         return self._request('POST', self.__url.path, postdata.encode('utf-8'))
 
     def _get_response(self):
-        http_response = self.__conn.getresponse()
+        try:
+            http_response = self.__conn.getresponse()
+        except socket.timeout as e:
+            raise JSONRPCException({
+                'code': -344,
+                'message': '%r RPC took longer than %f seconds. Consider '
+                           'using larger timeout for calls that take '
+                           'longer to return.' % (self._service_name,
+                                                  self.__conn.timeout)})
         if http_response is None:
             raise JSONRPCException({
                 'code': -342, 'message': 'missing HTTP response from server'})
-- 
cgit v1.2.3