Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Don't start a timer #172

Merged
merged 3 commits into from Aug 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -219,6 +219,7 @@ class Analytics {
const hasReachedQueueSize = this.queue.reduce((acc, item) => acc + JSON.stringify(item).length, 0) >= this.maxQueueSize
if (hasReachedFlushAt || hasReachedQueueSize) {
this.flush(callback)
return
}

if (this.flushInterval && !this.timer) {
Expand Down
16 changes: 16 additions & 0 deletions test.js
Expand Up @@ -267,6 +267,22 @@ test('enqueue - don\'t reset an existing timer', async t => {
t.true(client.flush.calledOnce)
})

test('enqueue - prevent flushing through time interval when already flushed by flushAt', async t => {
const client = createClient({ flushAt: 2, flushInterval: 10 })
client.flushed = false
spy(client, 'flush')

client.enqueue('type', {})
t.true(client.flush.calledOnce)

client.enqueue('type', {})
client.enqueue('type', {})
t.true(client.flush.calledTwice)

await delay(10)
t.true(client.flush.calledTwice)
})
Copy link
Contributor

@pbassut pbassut Jul 24, 2021

Choose a reason for hiding this comment

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

This test is not clear enough.
If I understood this correctly: even though it waited 10 seconds it didn't flush a third time because it had already flushed when it reached flushAt.
Maybe the title could be enqueue - prevent flushing through time interval when already flushed by flushAt


test('enqueue - extend context', t => {
const client = createClient()

Expand Down