Skip to content

Commit dfceba1

Browse files
undefinedclaude
andcommitted
Fix test flakiness from stale git locks after worker termination
- Wrap exec in runner.js to auto-remove index.lock before git commands - Add 1s delay after worker.terminate() to let native threads release locks Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f000025 commit dfceba1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

test/runner.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
var fse = require("fs-extra");
22
var path = require("path");
33
var local = path.join.bind(path, __dirname);
4-
var exec = require('../utils/execPromise');
4+
var _exec = require('../utils/execPromise');
55

66
var NodeGit = require('..');
77

88
var workdirPath = local("repos/workdir");
99
var constWorkdirPath = local("repos/constworkdir");
1010
var masterSha;
11+
12+
// Wrap exec to remove stale git locks before any git command
13+
function exec(command, opts) {
14+
if (opts && opts.cwd && command.startsWith("git ")) {
15+
try {
16+
fse.removeSync(path.join(opts.cwd, ".git", "index.lock"));
17+
} catch (e) {}
18+
}
19+
return _exec(command, opts);
20+
}
1121
var gitDir;
1222
var gitBackupDir;
1323

test/tests/worker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ if (Worker) {
101101
worker.on("error", () => {});
102102
worker.on("exit", (code) => {
103103
if (code === TERMINATED_EXIT_CODE) {
104-
done();
104+
// Delay to let native threads release locks after termination
105+
setTimeout(done, 1000);
105106
} else {
106107
assert.fail();
107108
}
@@ -144,7 +145,7 @@ if (Worker) {
144145
worker.on("error", () => {});
145146
worker.on("exit", (code) => {
146147
if (code === TERMINATED_EXIT_CODE && testOk === true) {
147-
done();
148+
setTimeout(done, 1000);
148149
}
149150
else {
150151
assert.fail();
@@ -217,7 +218,7 @@ if (Worker) {
217218
worker.on("error", () => {});
218219
worker.on("exit", (code) => {
219220
if (code === TERMINATED_EXIT_CODE && testOk === true) {
220-
done();
221+
setTimeout(done, 1000);
221222
}
222223
else {
223224
assert.fail();

0 commit comments

Comments
 (0)