Skip to content

Commit 813168d

Browse files
committed
fix(concurrent-access.test): remove broken performance assertion and simplify test
The "maintains performance with multiple readers" test wrapped synchronous SQLite operations in Promises, then used an unattached .then() callback for timing validation. Since Jest doesn't await unattached promises, the expect(totalTime).toBeLessThan(10000) assertion never executed - allowing the test to "pass" on ARM64 CI even when taking 60-140 seconds. Changes: - Remove pointless Promise wrapping (SQLite operations are synchronous) - Remove unenforced 10s performance assertion - Make mixed workload test's assertion platform-aware via getTimingMultiplier()
1 parent 81b43dd commit 813168d

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

test/concurrent-access.test.ts

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DatabaseSync } from "../src";
2-
import { useTempDir } from "./test-utils";
2+
import { getTimingMultiplier, useTempDir } from "./test-utils";
33

44
describe("Concurrent Access Patterns Tests", () => {
55
const { getDbPath } = useTempDir("sqlite-concurrent-test-", {
@@ -664,40 +664,31 @@ describe("Concurrent Access Patterns Tests", () => {
664664

665665
const startTime = Date.now();
666666

667-
// Each reader performs 100 queries
668-
const promises = readers.map((db, readerIndex) => {
669-
return new Promise<void>((resolve) => {
670-
const stmt = db.prepare(
671-
"SELECT * FROM perf_test WHERE category = ? AND value > ? LIMIT 20",
672-
);
673-
674-
for (let i = 0; i < 100; i++) {
675-
const category = (readerIndex * 10 + i) % 50;
676-
const value = Math.random() * 500;
677-
const results = stmt.all(category, value);
667+
// Each reader performs 100 queries (synchronously - SQLite is synchronous)
668+
readers.forEach((db, readerIndex) => {
669+
const stmt = db.prepare(
670+
"SELECT * FROM perf_test WHERE category = ? AND value > ? LIMIT 20",
671+
);
678672

679-
// Verify results make sense
680-
expect(Array.isArray(results)).toBe(true);
681-
expect(results.length).toBeLessThanOrEqual(20);
682-
}
673+
for (let i = 0; i < 100; i++) {
674+
const category = (readerIndex * 10 + i) % 50;
675+
const value = Math.random() * 500;
676+
const results = stmt.all(category, value);
683677

684-
resolve();
685-
});
678+
// Verify results make sense
679+
expect(Array.isArray(results)).toBe(true);
680+
expect(results.length).toBeLessThanOrEqual(20);
681+
}
686682
});
687683

688-
// Wait for all readers to complete (simulate concurrent execution)
689-
Promise.all(promises).then(() => {
690-
const endTime = Date.now();
691-
const totalTime = endTime - startTime;
692-
693-
// Performance check: should complete within reasonable time
694-
// This is a rough check - actual thresholds would depend on hardware
695-
expect(totalTime).toBeLessThan(10000); // 10 seconds max for 800 queries
684+
const endTime = Date.now();
685+
const totalTime = endTime - startTime;
696686

697-
console.log(
698-
`Concurrent read test completed in ${totalTime}ms (800 queries across 8 readers)`,
699-
);
700-
});
687+
// Log timing for informational purposes
688+
// Note: ARM64 CI runners can be significantly slower than x64
689+
console.log(
690+
`Concurrent read test completed in ${totalTime}ms (800 queries across 8 readers)`,
691+
);
701692

702693
// Close all readers
703694
readers.forEach((db) => db.close());
@@ -761,8 +752,9 @@ describe("Concurrent Access Patterns Tests", () => {
761752
const finalCounter = readStmt1.get();
762753
expect(finalCounter.counter).toBe(10); // 100/10 writes
763754

764-
// Performance check
765-
expect(totalTime).toBeLessThan(5000); // 5 seconds max
755+
// Performance check - allow more time on slower platforms (ARM64, Windows, etc.)
756+
const maxTime = 5000 * getTimingMultiplier();
757+
expect(totalTime).toBeLessThan(maxTime);
766758

767759
console.log(
768760
`Mixed workload test completed in ${totalTime}ms (100 iterations with reads and writes)`,

0 commit comments

Comments
 (0)