mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Reschedule Insights flushing after skipping for empty buffer (#14637)
This commit is contained in:
committed by
GitHub
parent
2ca742cb15
commit
513f20a902
@@ -544,6 +544,29 @@ describe('workflowExecuteAfterHandler - flushEvents', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('reschedule flush on no buffered insights', async () => {
|
||||
// ARRANGE
|
||||
jest.useFakeTimers();
|
||||
trxMock.insert.mockClear();
|
||||
insightsService.startBackgroundProcess();
|
||||
const flushEventsSpy = jest.spyOn(insightsService, 'flushEvents');
|
||||
|
||||
try {
|
||||
// ACT
|
||||
await jest.advanceTimersByTimeAsync(31 * 1000);
|
||||
|
||||
// ASSERT
|
||||
expect(flushEventsSpy).toHaveBeenCalledTimes(1);
|
||||
expect(trxMock.insert).not.toHaveBeenCalled();
|
||||
|
||||
// ACT
|
||||
await jest.advanceTimersByTimeAsync(31 * 1000);
|
||||
expect(flushEventsSpy).toHaveBeenCalledTimes(2);
|
||||
} finally {
|
||||
jest.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
test('flushes events to the database on shutdown', async () => {
|
||||
// ARRANGE
|
||||
trxMock.insert.mockClear();
|
||||
|
||||
@@ -259,6 +259,8 @@ export class InsightsService {
|
||||
async flushEvents() {
|
||||
// Prevent flushing if there are no events to flush
|
||||
if (this.bufferedInsights.size === 0) {
|
||||
// reschedule the timer to flush again
|
||||
this.startFlushingScheduler();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user