Skip to content

Commit f098cf2

Browse files
steipete8exgh
andcommitted
test(audit): restore observed SQLite methods without lint violations
Co-authored-by: Sean Bennett <[email protected]>
1 parent e6dd8fc commit f098cf2

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎src/audit/audit-event-writer.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function observeNonblockingSqliteTransactions(
3131
database: DatabaseSync,
3232
observed: number[],
3333
): () => void {
34-
const originalExec = database.exec;
34+
const originalExecDescriptor = Object.getOwnPropertyDescriptor(database, "exec");
35+
const originalExec = database.exec.bind(database);
3536
database.exec = (sql: string) => {
3637
if (sql === "BEGIN IMMEDIATE") {
3738
const busyTimeout = readSqliteBusyTimeout(database);
@@ -40,10 +41,15 @@ function observeNonblockingSqliteTransactions(
4041
throw new Error(`audit writer attempted a blocking SQLite transaction (${busyTimeout} ms)`);
4142
}
4243
}
43-
return originalExec.call(database, sql);
44+
return originalExec(sql);
4445
};
4546
return () => {
46-
database.exec = originalExec;
47+
if (originalExecDescriptor) {
48+
Object.defineProperty(database, "exec", originalExecDescriptor);
49+
return;
50+
}
51+
const ownDatabaseMethod: { exec?: DatabaseSync["exec"] } = database;
52+
delete ownDatabaseMethod.exec;
4753
};
4854
}
4955

@@ -297,7 +303,9 @@ describe("audit event writer", () => {
297303

298304
try {
299305
await writer.ready;
300-
await new Promise<void>((resolve) => setImmediate(resolve));
306+
await new Promise<void>((resolve) => {
307+
setImmediate(resolve);
308+
});
301309
expect(contender.isTransaction).toBe(true);
302310
expect(openedBusyTimeout).toBe(0);
303311
expect(observedBusyTimeouts).not.toHaveLength(0);
@@ -421,7 +429,9 @@ describe("audit event writer", () => {
421429
accepted: true,
422430
});
423431
expect(performance.now() - startedAt).toBeLessThan(250);
424-
await new Promise<void>((resolve) => setImmediate(resolve));
432+
await new Promise<void>((resolve) => {
433+
setImmediate(resolve);
434+
});
425435
expect(contender.isTransaction).toBe(true);
426436
expect(observedBusyTimeouts).not.toHaveLength(0);
427437
expect(observedBusyTimeouts.every((busyTimeout) => busyTimeout === 0)).toBe(true);

0 commit comments

Comments
 (0)