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 3cc6e35 commit 45c1692
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8"]

services:
redis:
Expand Down Expand Up @@ -49,6 +50,28 @@ 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

- name: Verify typehints
run: make lint

Expand Down
9 changes: 9 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,7 @@ def _load_file(self, path, all_data):
with open(path, 'r') as f:
content = f.read()
parsed = self._parse_content(content)

for key, flag in parsed.get('flags', {}).items():
_sanitize_json_item(flag)
self._add_item(all_data, FEATURES, flag)
Expand Down Expand Up @@ -165,6 +166,13 @@ def __init__(self, resolved_paths, reloader):

class LDWatchdogHandler(watchdog.events.FileSystemEventHandler):
def on_any_event(self, event):
if isinstance(event, watchdog.events.FileDeletedEvent):
return

if isinstance(event, watchdog.events.FileMovedEvent) and event.dest_path in watched_files:
reloader()
return

if event.src_path in watched_files:
reloader()

Expand Down Expand Up @@ -213,4 +221,5 @@ def _check_file_times(self):
ret[path] = os.path.getmtime(path)
except:
ret[path] = None

return ret
3 changes: 3 additions & 0 deletions ldclient/testing/test_file_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
from typing import List

from ldclient.impl.util import log

import pytest
import tempfile
import threading
Expand Down Expand Up @@ -236,6 +238,7 @@ def test_does_not_reload_modified_file_if_auto_update_is_off():

def do_auto_update_test(options):
path = make_temp_file(flag_only_json)

options['paths'] = path
try:
source = make_data_source(Config("SDK_KEY"), **options)
Expand Down

0 comments on commit 45c1692

Please sign in to comment.