Skip to content

Commit c90afdf

Browse files
committed
test(native-db): cover the remaining 3 busyTimeoutMs threading call sites (Greptile review)
Impact: 3 functions changed, 8 affected
1 parent 1e104f1 commit c90afdf

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/domain/graph/builder/stages/native-orchestrator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ async function runDataflowVertexPass(
556556
* Used when the Rust addon doesn't include analysis persistence (older addon
557557
* version) or when analysis failed on the Rust side.
558558
*/
559-
async function runPostNativeAnalysis(
559+
export async function runPostNativeAnalysis(
560560
ctx: PipelineContext,
561561
allFileSymbols: Map<string, ExtractorOutput>,
562562
changedFiles: string[] | undefined,
@@ -1950,7 +1950,7 @@ function backfillEdgeTechniquesAfterNativeOrchestrator(
19501950
* corruption. On setup failure, falls back to reopening better-sqlite3 and
19511951
* leaves ctx.nativeDb undefined so the caller falls through to the JS pipeline.
19521952
*/
1953-
function openNativeDatabase(ctx: PipelineContext): void {
1953+
export function openNativeDatabase(ctx: PipelineContext): void {
19541954
if (ctx.nativeDb || !ctx.nativeAvailable) return;
19551955
const native = loadNative();
19561956
if (!native?.NativeDatabase) return;

src/features/branch-compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface RawNodeRow {
117117
}
118118

119119
/** Try opening a NativeDatabase handle for batched fan-in/fan-out metrics. */
120-
function openNativeDbForFanMetrics(dbPath: string): NativeDatabase | undefined {
120+
export function openNativeDbForFanMetrics(dbPath: string): NativeDatabase | undefined {
121121
if (!isNativeAvailable()) return undefined;
122122
try {
123123
const native = getNative();

tests/unit/native-db-busy-timeout-threading.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ import {
6565
} from '../../src/db/index.js';
6666
import { PipelineContext } from '../../src/domain/graph/builder/context.js';
6767
import { reopenNativeDb } from '../../src/domain/graph/builder/stages/native-db-lifecycle.js';
68+
import {
69+
openNativeDatabase,
70+
runPostNativeAnalysis,
71+
} from '../../src/domain/graph/builder/stages/native-orchestrator.js';
72+
import { openNativeDbForFanMetrics } from '../../src/features/branch-compare.js';
6873

6974
let tmpDir: string;
7075
let dbPath: string;
@@ -119,3 +124,49 @@ describe('reopenNativeDb (build pipeline) threads ctx.config.db.busyTimeoutMs in
119124
expect(openReadWriteCalls[0]?.[1]).toBe(CUSTOM_BUSY_TIMEOUT_MS);
120125
});
121126
});
127+
128+
describe('openNativeDatabase (build pipeline) threads ctx.config.db.busyTimeoutMs into NativeDatabase.openReadWrite', () => {
129+
it('passes ctx.config.db.busyTimeoutMs to the native factory', () => {
130+
openReadWriteCalls.length = 0;
131+
const ctx = new PipelineContext();
132+
ctx.dbPath = dbPath;
133+
ctx.db = { close: () => {} } as PipelineContext['db'];
134+
ctx.nativeAvailable = true;
135+
ctx.config = { db: { busyTimeoutMs: CUSTOM_BUSY_TIMEOUT_MS } } as PipelineContext['config'];
136+
137+
openNativeDatabase(ctx);
138+
139+
expect(openReadWriteCalls).toHaveLength(1);
140+
expect(openReadWriteCalls[0]?.[1]).toBe(CUSTOM_BUSY_TIMEOUT_MS);
141+
});
142+
});
143+
144+
describe('runPostNativeAnalysis (build pipeline) threads ctx.config.db.busyTimeoutMs into NativeDatabase.openReadWrite', () => {
145+
it('passes ctx.config.db.busyTimeoutMs to the native factory', async () => {
146+
openReadWriteCalls.length = 0;
147+
const ctx = new PipelineContext();
148+
ctx.dbPath = dbPath;
149+
ctx.db = openDb(dbPath);
150+
ctx.rootDir = tmpDir;
151+
ctx.opts = { engine: 'native' };
152+
ctx.config = { db: { busyTimeoutMs: CUSTOM_BUSY_TIMEOUT_MS } } as PipelineContext['config'];
153+
154+
try {
155+
await runPostNativeAnalysis(ctx, new Map(), []);
156+
} finally {
157+
closeDb(ctx.db as Parameters<typeof closeDb>[0]);
158+
}
159+
160+
expect(openReadWriteCalls).toHaveLength(1);
161+
expect(openReadWriteCalls[0]?.[1]).toBe(CUSTOM_BUSY_TIMEOUT_MS);
162+
});
163+
});
164+
165+
describe('openNativeDbForFanMetrics (branch-compare) threads the configured busyTimeoutMs into NativeDatabase.openReadonly', () => {
166+
it('passes the configured busyTimeoutMs to the native factory', () => {
167+
openReadonlyCalls.length = 0;
168+
openNativeDbForFanMetrics(dbPath);
169+
expect(openReadonlyCalls).toHaveLength(1);
170+
expect(openReadonlyCalls[0]?.[1]).toBe(CUSTOM_BUSY_TIMEOUT_MS);
171+
});
172+
});

0 commit comments

Comments
 (0)