Skip to content

Commit dd9cbc6

Browse files
authored
Merge pull request #110 from reddit/set_timeout
Set default `timeout` for `path` watched to `30 seconds`
2 parents 0f073d0 + 5de334e commit dd9cbc6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

reddit_decider/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from copy import deepcopy
44
from dataclasses import dataclass
5+
from datetime import timedelta
56
from enum import Enum
67
from typing import Any
78
from typing import Callable
@@ -1209,9 +1210,10 @@ def decider_client_from_config(
12091210
``path`` (optional)
12101211
The path to the experiment configuration file generated by the
12111212
experiment configuration fetcher daemon.
1213+
Defaults to :code:`"/var/local/experiments.json"`.
12121214
``timeout`` (optional)
1213-
The time that we should wait for the file specified by ``path`` to
1214-
exist. Defaults to `None` which is not blocking.
1215+
The time that we should wait for the file specified by ``path`` to exist.
1216+
Defaults to blocking for :code:`30` seconds.
12151217
``backoff`` (optional)
12161218
The base amount of time for exponential backoff when trying to find the
12171219
experiments config file. Defaults to no backoff between tries.
@@ -1231,7 +1233,7 @@ def decider_client_from_config(
12311233
{
12321234
config_prefix: {
12331235
"path": config.Optional(config.String, default="/var/local/experiments.json"),
1234-
"timeout": config.Optional(config.Timespan),
1236+
"timeout": config.Optional(config.Timespan, default=timedelta(seconds=30)),
12351237
"backoff": config.Optional(config.Timespan),
12361238
}
12371239
},

tests/decider_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ def setUp(self):
8888
self.mock_span = mock.MagicMock(spec=ServerSpan)
8989
self.mock_span.context = None
9090

91-
def test_make_clients(self, file_watcher_mock):
91+
def test_make_client_without_timeout_set(self, file_watcher_mock):
9292
with create_temp_config_file({}) as f:
9393
decider_ctx_factory = decider_client_from_config(
9494
{"experiments.path": f.name}, self.event_logger
9595
)
9696
self.assertIsInstance(decider_ctx_factory, DeciderContextFactory)
9797
file_watcher_mock.assert_called_once_with(
98-
path=f.name, parser=init_decider_parser, timeout=None, backoff=None
98+
path=f.name, parser=init_decider_parser, timeout=30.0, backoff=None
9999
)
100100

101101
def test_timeout(self, file_watcher_mock):

0 commit comments

Comments
 (0)