Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions test/tests/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,49 @@ describe("Clone", function() {
var Repository = NodeGit.Repository;
var Clone = NodeGit.Clone;

var clonePath = local("../repos/clone");
var longClonePath = generatePathWithLength(clonePath, 600);
var clonePath;
var longClonePath;
var cloneSeq = 0;

var sshPublicKeyPath = local("../id_rsa.pub");
var sshPrivateKeyPath = local("../id_rsa");
var sshEncryptedPublicKeyPath = local("../encrypted_rsa.pub");
var sshEncryptedPrivateKeyPath = local("../encrypted_rsa");

// Set a reasonable timeout here now that our repository has grown.
this.timeout(30000);
// macos-15-intel has stalled a fetch of nodegit/test past 30s while libgit2
// was still writing the pack. Mocha does not cancel that clone on timeout.
// Each attempt uses its own directory, removed only after that clone
// settles, so a timed-out attempt cannot make the next test fail with
// ENOENT while creating a pack lock file. One retry covers a stalled fetch.
this.timeout(60000);
this.retries(1);

beforeEach(function() {
return fse.remove(clonePath)
.then(function() {
return fse.remove(longClonePath);
})
.catch(function(err) {
console.log(err);
throw err;
});
cloneSeq += 1;
clonePath = local("../repos/clone-" + cloneSeq);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
longClonePath = generatePathWithLength(clonePath, 600);

var test = this.currentTest;
if (test.fn._clonePathWrapped) {
return;
}

var original = test.fn;
var wrapped = function() {
var dir = clonePath;
var longDir = longClonePath;
var result = original.apply(this, arguments);
if (result && typeof result.then === "function") {
result.then(function() {
return Promise.all([fse.remove(dir), fse.remove(longDir)]);
}, function() {
return Promise.all([fse.remove(dir), fse.remove(longDir)]);
}).catch(function() {});
}
return result;
};
wrapped._clonePathWrapped = true;
test.fn = wrapped;
});

it.skip("can clone with http", function() {
Expand Down Expand Up @@ -83,6 +106,10 @@ describe("Clone", function() {
it("can clone twice with https using same config object", function() {
var test = this;
var url = "https://github.com/nodegit/test.git";
// Keep this attempt's directory. A retry replaces clonePath while the
// first clone can still be finishing, and this chain removes that path
// before cloning into it again.
var dest = clonePath;
var progressCount = 0;
var opts = {
fetchOpts: {
Expand All @@ -94,15 +121,15 @@ describe("Clone", function() {
}
};

return Clone(url, clonePath, opts)
return Clone(url, dest, opts)
.then(function(repo) {
assert.ok(repo instanceof Repository);
assert.notEqual(progressCount, 0);
return fse.remove(clonePath);
return fse.remove(dest);
})
.then(function() {
progressCount = 0;
return Clone(url, clonePath, opts);
return Clone(url, dest, opts);
})
.then(function(repo) {
assert.ok(repo instanceof Repository);
Expand Down Expand Up @@ -244,6 +271,7 @@ describe("Clone", function() {
var old_pageant = local("../../vendor/pageant_sha1.exe");
var privateKey = local("../../vendor/private.ppk");
var test = this;
var dest = clonePath;
var url = "git@github.com:nodegit/test.git";
var opts = {
fetchOpts: {
Expand Down Expand Up @@ -273,7 +301,7 @@ describe("Clone", function() {
}

try {
const repo = await Clone(url, clonePath, opts);
const repo = await Clone(url, dest, opts);
test.repository = repo;
} catch(e) {
return assert.fail("Clone error: " + e.message);
Expand Down
119 changes: 61 additions & 58 deletions test/tests/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require("path");
const assert = require("assert");
const fse = require("fs-extra");
const local = path.join.bind(path, __dirname);
const NodeGit = require("../../");
Expand All @@ -13,17 +12,42 @@ try {

if (Worker) {
describe("Worker", function() {
const clonePath = local("../repos/clone");
let cloneSeq = 0;
let clonePath;

// Set a reasonable timeout here now that our repository has grown.
// Same directory isolation as the Clone suite. A worker that is still
// inside libgit2 after Mocha times out must not share test/repos/clone
// with the next test. One retry covers the intermittent hang in
// worker.terminate() during checkout on macos-15-intel.
this.timeout(30000);
this.retries(1);

beforeEach(function() {
return fse.remove(clonePath).catch(function(err) {
console.log(err);

throw err;
function startWorker(scriptPath) {
const dir = clonePath;
const worker = new Worker(scriptPath, {
workerData: {
clonePath: dir,
url: "https://github.com/nodegit/test.git"
}
});
worker.on("exit", function() {
fse.remove(dir).catch(function() {});
});
return worker;
}

// assert.fail() in a late "exit" handler throws into whatever test is
// running after a timeout. Mocha ignores a late done() once timedOut is set.
function callDone(test, done, err) {
if (test.timedOut || test.state === "passed" || test.state === "failed") {
return;
}
done(err);
}

beforeEach(function() {
cloneSeq += 1;
clonePath = local("../repos/clone-worker-" + cloneSeq);
});

afterEach(function() {
Expand All @@ -36,62 +60,56 @@ if (Worker) {
});

it("can perform basic functionality via worker thread", function(done) {
const workerPath = local("../utils/worker.js");
const worker = new Worker(workerPath, {
workerData: {
clonePath,
url: "https://github.com/nodegit/test.git"
}
});
const test = this;
const worker = startWorker(local("../utils/worker.js"));
worker.on("message", (message) => {
switch (message) {
case "init":
break;
case "success":
done();
callDone(test, done);
break;
case "failure":
assert.fail();
callDone(test, done, new Error("worker reported failure"));
break;
}
});
worker.on("error", () => assert.fail());
worker.on("error", () => {
callDone(test, done, new Error("worker error"));
});
worker.on("exit", (code) => {
if (code !== 0) {
assert.fail();
callDone(test, done, new Error("worker exited with code " + code));
}
});
});

for (let i = 0; i < 5; ++i) {
// disabled until we can address flakiness
it.skip(`can kill worker thread while in use #${i}`, function(done) { // jshint ignore:line
const workerPath = local("../utils/worker.js");
const worker = new Worker(workerPath, {
workerData: {
clonePath,
url: "https://github.com/nodegit/test.git"
}
});
const test = this;
const worker = startWorker(local("../utils/worker.js"));
worker.on("message", (message) => {
switch (message) {
case "init":
setTimeout(() => { worker.terminate(); }, 500);
break;
case "success":
assert.fail();
callDone(test, done, new Error("worker reported success"));
break;
case "failure":
assert.fail();
callDone(test, done, new Error("worker reported failure"));
break;
}
});
worker.on("error", () => assert.fail());
worker.on("error", () => {
callDone(test, done, new Error("worker error"));
});
worker.on("exit", (code) => {
if (code === 1) {
done();
callDone(test, done);
} else {
assert.fail();
callDone(test, done, new Error("worker exited with code " + code));
}
});
});
Expand Down Expand Up @@ -119,13 +137,7 @@ if (Worker) {
settled = true;
done(err);
}
const workerPath = local("../utils/worker_context_aware.js");
const worker = new Worker(workerPath, {
workerData: {
clonePath,
url: "https://github.com/nodegit/test.git"
}
});
const worker = startWorker(local("../utils/worker_context_aware.js"));
worker.on("message", (message) => {
if (settled) {
return;
Expand Down Expand Up @@ -159,13 +171,8 @@ if (Worker) {
// is terminated, node exits gracefully. To make sure we terminate the
// worker during a checkout, continuous checkouts will be running in a loop.
it("can kill worker thread while doing a checkout and exit gracefully", function(done) { // jshint ignore:line
const workerPath = local("../utils/worker_checkout.js");
const worker = new Worker(workerPath, {
workerData: {
clonePath,
url: "https://github.com/nodegit/test.git"
}
});
const test = this;
const worker = startWorker(local("../utils/worker_checkout.js"));
worker.on("message", (message) => {
switch (message) {
case "init":
Expand All @@ -174,19 +181,21 @@ if (Worker) {
setTimeout(() => { worker.terminate(); }, 10000);
break;
case "success":
assert.fail();
callDone(test, done, new Error("worker reported success"));
break;
case "failure":
assert.fail();
callDone(test, done, new Error("worker reported failure"));
break;
}
});
worker.on("error", () => assert.fail());
worker.on("error", () => {
callDone(test, done, new Error("worker error"));
});
worker.on("exit", (code) => {
if (code == 1) {
done();
if (code === 1) {
callDone(test, done);
} else {
assert.fail();
callDone(test, done, new Error("worker exited with code " + code));
}
});
});
Expand All @@ -207,13 +216,7 @@ if (Worker) {
settled = true;
done(err);
}
const workerPath = local("../utils/worker_context_aware_checkout.js");
const worker = new Worker(workerPath, {
workerData: {
clonePath,
url: "https://github.com/nodegit/test.git"
}
});
const worker = startWorker(local("../utils/worker_context_aware_checkout.js"));
worker.on("message", (message) => {
if (settled) {
return;
Expand Down
Loading