Skip to content

Commit

Permalink
test: Atomically update file data source file
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Aug 13, 2024
1 parent 4bfcdb8 commit c8b0f33
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ jobs:
- name: Run tests
run: make test

- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test
- run: make test

- name: Verify typehints
run: make lint

Expand Down
5 changes: 5 additions & 0 deletions ldclient/impl/integrations/files/file_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def _load_file(self, path, all_data):
with open(path, 'r') as f:
content = f.read()
parsed = self._parse_content(content)

if type(parsed) is not dict:
parsed = {}

for key, flag in parsed.get('flags', {}).items():
_sanitize_json_item(flag)
self._add_item(all_data, FEATURES, flag)
Expand Down Expand Up @@ -213,4 +217,5 @@ def _check_file_times(self):
ret[path] = os.path.getmtime(path)
except:
ret[path] = None

return ret
4 changes: 2 additions & 2 deletions ldclient/testing/test_file_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def make_temp_file(content):
return path

def replace_file(path, content):
with open(path, 'w') as f:
f.write(content)
temp_path = make_temp_file(content)
os.rename(temp_path, path)

def test_does_not_load_data_prior_to_start():
path = make_temp_file('{"flagValues":{"key":"value"}}')
Expand Down

0 comments on commit c8b0f33

Please sign in to comment.