Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ldclient/impl/datasource/async_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ async def _process_message(self, msg: Event) -> bool:
path = payload['path']
# noinspection PyShadowingNames
version = payload['version']
if isinstance(version, bool) or not isinstance(version, int):
raise ValueError("delete event for %s has a version that is not an integer" % path)
log.debug("Received delete event for %s, New version: [%d]", path, version)
parsed = parse_path(path)
if parsed is not None:
Expand Down
2 changes: 2 additions & 0 deletions ldclient/impl/datasource/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def _process_message(self, store, msg: Event) -> bool:
path = payload['path']
# noinspection PyShadowingNames
version = payload['version']
if isinstance(version, bool) or not isinstance(version, int):
raise ValueError("delete event for %s has a version that is not an integer" % path)
log.debug("Received delete event for %s, New version: [%d]", path, version)
target = parse_path(path)
if target is not None:
Expand Down
14 changes: 14 additions & 0 deletions ldclient/testing/impl/datasource/test_async_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ async def test_delete_event_removes_item_from_store():
await proc.stop()


@pytest.mark.asyncio
async def test_delete_event_with_version_that_is_not_an_integer_restarts_stream():
put_data = _make_put_data()
delete_data = _make_delete_data(FEATURES, 'f1', 'no')
actions = [_start(), _event('put', put_data), _event('delete', delete_data)]

# Run the processor until it handles the delete.
proc, store, ready, factory = await _run_with_actions(actions, retry_state=_fast_retry_state())
# The processor drops the stream.
await _wait_until(lambda: factory.created[0].interrupted)

await proc.stop()


@pytest.mark.asyncio
async def test_fault_with_error_does_not_set_ready_by_itself():
"""A Fault that arrives before any put must not mark the processor as initialized."""
Expand Down
32 changes: 32 additions & 0 deletions ldclient/testing/impl/datasource/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@ def test_receives_delete_events():
expect_delete(store, SEGMENTS, segmentv1['key'])


def test_restarts_stream_if_delete_event_version_is_not_an_integer():
store = InMemoryFeatureStore()
ready = Event()
flagv1 = FlagBuilder('flagkey').version(1).build()

with start_server() as server:
with stream_content(make_put_event()) as stream1, stream_content(make_put_event([flagv1])) as stream2:
config = Config(sdk_key='sdk-key', stream_uri=server.uri, initial_reconnect_delay=brief_delay)

listeners = Listeners()

def listener(s):
# The test server serves one request at a time, so end the first stream when the SDK reports an error.
if s.error is not None:
stream1.close()

listeners.add(listener)

config._data_source_update_sink = DataSourceUpdateSinkImpl(store, listeners, Listeners())
server.for_path('/all', SequentialHandler(stream1, stream2))

with StreamingUpdateProcessor(config, store, ready, None) as sp:
sp.start()
ready.wait(start_wait)
assert sp.initialized()

# Send a delete whose version is a string.
stream1.push(make_delete_event(FEATURES, flagv1['key'], 'no'))
# The SDK drops the stream and gets the data again on a new connection.
expect_update(store, FEATURES, flagv1)


def test_reconnects_if_stream_is_broken():
store = InMemoryFeatureStore()
ready = Event()
Expand Down
Loading