Skip to content

Commit c8b0f33

Browse files
committed
test: Atomically update file data source file
1 parent 4bfcdb8 commit c8b0f33

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

.github/workflows/ci.yml

+24
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ jobs:
4949
- name: Run tests
5050
run: make test
5151

52+
- run: make test
53+
- run: make test
54+
- run: make test
55+
- run: make test
56+
- run: make test
57+
- run: make test
58+
- run: make test
59+
- run: make test
60+
- run: make test
61+
- run: make test
62+
- run: make test
63+
- run: make test
64+
- run: make test
65+
- run: make test
66+
- run: make test
67+
- run: make test
68+
- run: make test
69+
- run: make test
70+
- run: make test
71+
- run: make test
72+
- run: make test
73+
- run: make test
74+
- run: make test
75+
5276
- name: Verify typehints
5377
run: make lint
5478

ldclient/impl/integrations/files/file_data_source.py

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ def _load_file(self, path, all_data):
112112
with open(path, 'r') as f:
113113
content = f.read()
114114
parsed = self._parse_content(content)
115+
116+
if type(parsed) is not dict:
117+
parsed = {}
118+
115119
for key, flag in parsed.get('flags', {}).items():
116120
_sanitize_json_item(flag)
117121
self._add_item(all_data, FEATURES, flag)
@@ -213,4 +217,5 @@ def _check_file_times(self):
213217
ret[path] = os.path.getmtime(path)
214218
except:
215219
ret[path] = None
220+
216221
return ret

ldclient/testing/test_file_data_source.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def make_temp_file(content):
117117
return path
118118

119119
def replace_file(path, content):
120-
with open(path, 'w') as f:
121-
f.write(content)
120+
temp_path = make_temp_file(content)
121+
os.rename(temp_path, path)
122122

123123
def test_does_not_load_data_prior_to_start():
124124
path = make_temp_file('{"flagValues":{"key":"value"}}')

0 commit comments

Comments
 (0)