Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fungairino committed Sep 23, 2024
1 parent 0846258 commit 99fcb06
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/telemetry/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,41 @@ describe("logging", () => {
await expect(count()).resolves.toBe(1);
});

test("sweep", async () => {
test("sweepLogs", async () => {
// Set up test log database that will trigger sweepLogs due to count > MAX_LOG_RECORDS
// sweepLog assertions are all written in one test due to this expensive setup
flagOnMock.mockResolvedValue(false);
await Promise.all(
array(logEntryFactory, 1500)().map(async (x) => {
array(logEntryFactory, 1300)().map(async (x) => {
await appendEntry(x);
}),
);

// Verify that when the DISABLE_IDB_LOGGING flag is on, the logs are not swept
mockFlag(FeatureFlags.DISABLE_IDB_LOGGING);
await sweepLogs();
await expect(count()).resolves.toBe(1500);
await expect(count()).resolves.toBe(1300);

flagOnMock.mockResolvedValue(false);

// Verify that sweeper will abort if timeout is hit
const consoleWarnSpy = jest.spyOn(console, "warn");
const originalTimeout = global.setTimeout;
// Simulate timeout by mocking setTimeout to immediately call the abort signal
const setTimeoutSpy = jest
.spyOn(global, "setTimeout")
.mockImplementation((fn) => originalTimeout(fn, 0));
await sweepLogs();
await expect(count()).resolves.toBeGreaterThan(1250);
expect(consoleWarnSpy).toHaveBeenCalledWith(
"Log sweep aborted due to timeout",
);
setTimeoutSpy.mockRestore();

// Verify sweepLogs functionality
await sweepLogs();
await expect(count()).resolves.toBe(937);
// Increase timeout so test isn't flakey on CI due to slow append operation
// Increase timeout so test isn't flaky on CI due to slow append operation
}, 25_000);

test("getLogEntries by modId", async () => {
Expand Down

0 comments on commit 99fcb06

Please sign in to comment.