Skip to content

Commit 46b1fea

Browse files
committed
Update backend socket timeout
* Increase the default timeout to 60 seconds for higher resilience at the small risk of longer hanging CI jobs. * Make the default timeout configurable via the environment variable `TEST_BACKEND_TIMEOUT`
1 parent 90efae2 commit 46b1fea

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Environment variables:
3939
you also need to set:
4040
* `TEST_AWS_ECR_URI`
4141
The URL to the docker container registry where nightly builds are stored.
42+
* `TEST_BACKEND_TIMEOUT`
43+
The default socket timeout to use when waiting for the TestKit backend to
44+
respond. This can be any finite float value (in seconds).
45+
The default is `60.0` seconds.
4246

4347
```console
4448
export TEST_DRIVER_NAME=go
@@ -120,7 +124,8 @@ TestKit or for debugging local backends:
120124
Set to `1` to disable TestKit timing out if the backend takes longer than
121125
the usually enforced timeout. This is very handy if you want to step through
122126
the backend or driver with a debugger without TestKit canceling the tests
123-
due to a timed out connection.
127+
due to a timed out connection.
128+
You may not set this variable if `TEST_BACKEND_TIMEOUT` is already set.
124129

125130

126131
### Running tests against a specific backend

nutkit/backend/backend.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import json
3+
import math
34
import os
45
import socket
56
from contextlib import contextmanager
@@ -10,11 +11,9 @@
1011
PROTOCOL_CLASSES = dict(
1112
m for m in inspect.getmembers(protocol, inspect.isclass)
1213
)
13-
DEBUG_MESSAGES = os.environ.get("TEST_DEBUG_REQRES", "0").lower() in (
14-
"1", "y", "yes", "true", "t", "on"
15-
)
16-
DEBUG_TIMEOUT = os.environ.get("TEST_DEBUG_NO_BACKEND_TIMEOUT", "0") in (
17-
"1", "y", "yes", "true", "t", "on"
14+
DEBUG_MESSAGES = (
15+
os.environ.get("TEST_DEBUG_REQRES").lower()
16+
in ("1", "y", "yes", "true", "t", "on")
1817
)
1918

2019

@@ -41,8 +40,35 @@ def decode_hook(x):
4140
return PROTOCOL_CLASSES[name](**data)
4241

4342

43+
def _get_default_backend_timeout():
44+
test_debug_no_backend_timeout = (
45+
os.environ.get("TEST_DEBUG_NO_BACKEND_TIMEOUT").lower()
46+
in ("1", "y", "yes", "true", "t", "on")
47+
)
48+
default_timeout = os.environ.get("TEST_BACKEND_TIMEOUT")
49+
if test_debug_no_backend_timeout:
50+
if default_timeout is not None:
51+
raise Exception(
52+
"TEST_BACKEND_TIMEOUT and TEST_DEBUG_NO_BACKEND_TIMEOUT "
53+
"are mutually exclusive"
54+
)
55+
return None
56+
if default_timeout is None:
57+
return 60.0
58+
try:
59+
default_timeout = float(default_timeout)
60+
if not math.isfinite(default_timeout):
61+
raise ValueError("not finite")
62+
except (TypeError, ValueError) as e:
63+
raise Exception(
64+
"TEST_BACKEND_TIMEOUT must be a finite float, "
65+
f"got {default_timeout}: {e}"
66+
)
67+
return default_timeout
68+
69+
4470
# How long to wait before backend responds
45-
DEFAULT_TIMEOUT = None if DEBUG_TIMEOUT else 10
71+
DEFAULT_TIMEOUT = _get_default_backend_timeout()
4672

4773

4874
class Backend:

0 commit comments

Comments
 (0)