Skip to content

Commit 884f293

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

File tree

3 files changed

+94
-59
lines changed

3 files changed

+94
-59
lines changed

.github/workflows/ci.yml

+82-59
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
20+
# python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
21+
python-version: ["3.8"]
2122

2223
services:
2324
redis:
@@ -49,6 +50,28 @@ jobs:
4950
- name: Run tests
5051
run: make test
5152

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+
5275
- name: Verify typehints
5376
run: make lint
5477

@@ -67,61 +90,61 @@ jobs:
6790
test_service_port: 9000
6891
token: ${{ secrets.GITHUB_TOKEN }}
6992

70-
windows:
71-
runs-on: windows-latest
72-
73-
defaults:
74-
run:
75-
shell: powershell
76-
77-
strategy:
78-
fail-fast: false
79-
matrix:
80-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
81-
82-
steps:
83-
- uses: actions/checkout@v4
84-
- name: Set up Python ${{ matrix.python-version }}
85-
uses: actions/setup-python@v4
86-
with:
87-
python-version: ${{ matrix.python-version }}
88-
89-
- name: Setup DynamoDB
90-
run: |
91-
$ProgressPreference = "SilentlyContinue"
92-
iwr -outf dynamo.zip https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip
93-
mkdir dynamo
94-
Expand-Archive -Path dynamo.zip -DestinationPath dynamo
95-
cd dynamo
96-
cmd /c "START /b java -Djava.library.path=./DynamoDBLocal_lib -jar ./DynamoDBLocal.jar"
97-
98-
- name: Setup Consul
99-
run: |
100-
$ProgressPreference = "SilentlyContinue"
101-
iwr -outf consul.zip https://releases.hashicorp.com/consul/1.4.2/consul_1.4.2_windows_amd64.zip
102-
mkdir consul
103-
Expand-Archive -Path consul.zip -DestinationPath consul
104-
cd consul
105-
sc.exe create "Consul" binPath="$(Get-Location)/consul.exe agent -dev"
106-
sc.exe start "Consul"
107-
108-
- name: Setup Redis
109-
run: |
110-
$ProgressPreference = "SilentlyContinue"
111-
iwr -outf redis.zip https://github.com/MicrosoftArchive/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip
112-
mkdir redis
113-
Expand-Archive -Path redis.zip -DestinationPath redis
114-
cd redis
115-
./redis-server --service-install
116-
./redis-server --service-start
117-
Start-Sleep -s 5
118-
./redis-cli ping
119-
120-
- name: Install poetry
121-
uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439
122-
123-
- name: Install requirements
124-
run: poetry install --all-extras
125-
126-
- name: Run tests
127-
run: make test
93+
# windows:
94+
# runs-on: windows-latest
95+
#
96+
# defaults:
97+
# run:
98+
# shell: powershell
99+
#
100+
# strategy:
101+
# fail-fast: false
102+
# matrix:
103+
# python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
104+
#
105+
# steps:
106+
# - uses: actions/checkout@v4
107+
# - name: Set up Python ${{ matrix.python-version }}
108+
# uses: actions/setup-python@v4
109+
# with:
110+
# python-version: ${{ matrix.python-version }}
111+
#
112+
# - name: Setup DynamoDB
113+
# run: |
114+
# $ProgressPreference = "SilentlyContinue"
115+
# iwr -outf dynamo.zip https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip
116+
# mkdir dynamo
117+
# Expand-Archive -Path dynamo.zip -DestinationPath dynamo
118+
# cd dynamo
119+
# cmd /c "START /b java -Djava.library.path=./DynamoDBLocal_lib -jar ./DynamoDBLocal.jar"
120+
#
121+
# - name: Setup Consul
122+
# run: |
123+
# $ProgressPreference = "SilentlyContinue"
124+
# iwr -outf consul.zip https://releases.hashicorp.com/consul/1.4.2/consul_1.4.2_windows_amd64.zip
125+
# mkdir consul
126+
# Expand-Archive -Path consul.zip -DestinationPath consul
127+
# cd consul
128+
# sc.exe create "Consul" binPath="$(Get-Location)/consul.exe agent -dev"
129+
# sc.exe start "Consul"
130+
#
131+
# - name: Setup Redis
132+
# run: |
133+
# $ProgressPreference = "SilentlyContinue"
134+
# iwr -outf redis.zip https://github.com/MicrosoftArchive/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip
135+
# mkdir redis
136+
# Expand-Archive -Path redis.zip -DestinationPath redis
137+
# cd redis
138+
# ./redis-server --service-install
139+
# ./redis-server --service-start
140+
# Start-Sleep -s 5
141+
# ./redis-cli ping
142+
#
143+
# - name: Install poetry
144+
# uses: abatilo/actions-poetry@7b6d33e44b4f08d7021a1dee3c044e9c253d6439
145+
#
146+
# - name: Install requirements
147+
# run: poetry install --all-extras
148+
#
149+
# - name: Run tests
150+
# run: make test

ldclient/impl/integrations/files/file_data_source.py

+9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ 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+
115116
for key, flag in parsed.get('flags', {}).items():
116117
_sanitize_json_item(flag)
117118
self._add_item(all_data, FEATURES, flag)
@@ -165,6 +166,13 @@ def __init__(self, resolved_paths, reloader):
165166

166167
class LDWatchdogHandler(watchdog.events.FileSystemEventHandler):
167168
def on_any_event(self, event):
169+
if isinstance(event, watchdog.events.FileDeletedEvent):
170+
return
171+
172+
if isinstance(event, watchdog.events.FileMovedEvent) and event.dest_path in watched_files:
173+
reloader()
174+
return
175+
168176
if event.src_path in watched_files:
169177
reloader()
170178

@@ -213,4 +221,5 @@ def _check_file_times(self):
213221
ret[path] = os.path.getmtime(path)
214222
except:
215223
ret[path] = None
224+
216225
return ret

ldclient/testing/test_file_data_source.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
from typing import List
44

5+
from ldclient.impl.util import log
6+
57
import pytest
68
import tempfile
79
import threading
@@ -236,6 +238,7 @@ def test_does_not_reload_modified_file_if_auto_update_is_off():
236238

237239
def do_auto_update_test(options):
238240
path = make_temp_file(flag_only_json)
241+
239242
options['paths'] = path
240243
try:
241244
source = make_data_source(Config("SDK_KEY"), **options)

0 commit comments

Comments
 (0)