From 1c63b9773d4cb9269bcbdba6b4cbecad820c51f3 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 1 Feb 2024 11:02:07 +0000 Subject: [PATCH] fix: real time polling even if empty (#20077) * fix: real time polling even if empty * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .../player/sessionRecordingDataLogic.test.ts | 32 ++++++++++++++++++- .../player/sessionRecordingDataLogic.ts | 5 +++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts index 77f82b9fa1c97..48068e668c112 100644 --- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts +++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts @@ -52,15 +52,21 @@ describe('sessionRecordingDataLogic', () => { if (req.url.searchParams.get('source') === 'blob') { return res(ctx.text(snapshotsAsJSONLines())) } else if (req.url.searchParams.get('source') === 'realtime') { + if (req.params.id === 'has-only-empty-realtime') { + return res(ctx.json({ snapshots: [] })) + } // ... since this is fake, we'll just return the same data in the right format return res(ctx.json(snapshotsAsRealTimeJSONPayload())) } // with no source requested should return sources - const sources = [BLOB_SOURCE] + let sources = [BLOB_SOURCE] if (req.params.id === 'has-real-time-too') { sources.push(REALTIME_SOURCE) } + if (req.params.id === 'has-only-empty-realtime') { + sources = [REALTIME_SOURCE] + } return [ 200, { @@ -393,4 +399,28 @@ describe('sessionRecordingDataLogic', () => { }) }) }) + + describe('empty realtime loading', () => { + beforeEach(async () => { + logic = sessionRecordingDataLogic({ + sessionRecordingId: 'has-only-empty-realtime', + // we don't want to wait for the default real time polling interval in tests + realTimePollingIntervalMilliseconds: 10, + }) + logic.mount() + // Most of these tests assume the metadata is being loaded upfront which is the typical case + logic.actions.loadRecordingMeta() + }) + + it('should start polling even though realtime is empty', async () => { + await expectLogic(logic, () => { + logic.actions.loadRecordingSnapshots() + }).toDispatchActions([ + 'loadRecordingSnapshotsSuccess', + 'startRealTimePolling', + 'pollRecordingSnapshots', + 'pollRecordingSnapshotsSuccess', + ]) + }) + }) }) diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.ts index 256b889eb926b..28243631dc597 100644 --- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.ts +++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.ts @@ -329,6 +329,11 @@ export const sessionRecordingDataLogic = kea([ source: sources[0], }) + // If we only have a realtime source and its empty, start polling it anyway + if (sources[0].source === SnapshotSourceType.realtime) { + actions.startRealTimePolling() + } + return }