Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sessionRecording bug #234

Merged
merged 2 commits into from
May 25, 2021
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
28 changes: 28 additions & 0 deletions src/__tests__/request-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,32 @@ describe('RequestQueue', () => {
{ transport: 'sendbeacon' }
)
})

it('handles unload with batchKeys', () => {
given.queue.enqueue('/e', { event: 'foo', timestamp: 1_610_000_000 }, { transport: 'XHR' })
given.queue.enqueue('/identify', { event: '$identify', timestamp: 1_620_000_000 })
given.queue.enqueue('/e', { event: 'bar', timestamp: 1_630_000_000 })
given.queue.enqueue('/e', { event: 'zeta', timestamp: 1_640_000_000 }, { _batchKey: 'sessionRecording' })

given.queue.unload()

expect(given.handlePollRequest).toHaveBeenCalledTimes(3)
expect(given.handlePollRequest).toHaveBeenCalledWith(
'/e',
[
{ event: 'foo', timestamp: 1_610_000_000 },
{ event: 'bar', timestamp: 1_630_000_000 },
],
{ transport: 'sendbeacon' }
)
expect(given.handlePollRequest).toHaveBeenCalledWith(
'/identify',
[{ event: '$identify', timestamp: 1_620_000_000 }],
{ transport: 'sendbeacon' }
)
expect(given.handlePollRequest).toHaveBeenCalledWith('/e', [{ event: 'zeta', timestamp: 1_640_000_000 }], {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the old code, this would be called with ('sessionRecording', data, options)

_batchKey: 'sessionRecording',
transport: 'sendbeacon',
})
})
})
4 changes: 2 additions & 2 deletions src/request-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class RequestQueue {
clearTimeout(this._poller)
const requests = this._event_queue.length > 0 ? this.formatQueue() : {}
this._event_queue.length = 0
for (let url in requests) {
const { data, options } = requests[url]
for (let key in requests) {
const { url, data, options } = requests[key]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. There are tests under src/tests/request-queue.js - mind adding one or editing existing ones in a way which demonstrates the problem? E.g. how was enqueue called in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, that was the first item for today!

It's kinda unfortunate: we had a similar test for poll that works, but didn't have one for unload.

this.handlePollRequest(url, data, { ...options, transport: 'sendbeacon' })
}
}
Expand Down