-
Notifications
You must be signed in to change notification settings - Fork 698
Expand file tree
/
Copy pathworker_context_aware.js
More file actions
74 lines (62 loc) · 1.98 KB
/
Copy pathworker_context_aware.js
File metadata and controls
74 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const {
isMainThread,
parentPort,
workerData
} = require("worker_threads");
const garbageCollect = require("./garbage_collect.js");
const assert = require("assert");
const NodeGit = require("../../");
const { promisify } = require("util");
if (isMainThread) {
throw new Error("Must be run via worker thread");
}
const { clonePath, url } = workerData;
const opts = {
fetchOpts: {
callbacks: {
certificateCheck: () => 0
}
}
};
let repository;
const oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
return NodeGit.Clone(url, clonePath, opts)
.then((_repository) => {
repository = _repository;
assert.ok(repository instanceof NodeGit.Repository);
return repository.getCommit(oid);
}).then((commit) => {
assert.ok(commit instanceof NodeGit.Commit);
var historyCount = 0;
var history = commit.history();
history.on("commit", function(commit) {
// Number of commits is known to be higher than 200
if (++historyCount == 200) {
// Tracked objects must work too when the Garbage Collector is triggered
garbageCollect();
// Count total of objects left after being created/destroyed
const freeingCount =
NodeGit.Cert.getNonSelfFreeingConstructedCount() +
NodeGit.Repository.getSelfFreeingInstanceCount() +
NodeGit.Commit.getSelfFreeingInstanceCount() +
NodeGit.Oid.getSelfFreeingInstanceCount() +
NodeGit.Revwalk.getSelfFreeingInstanceCount();
const numberOfTrackedObjects = NodeGit.getNumberOfTrackedObjects();
if (freeingCount === numberOfTrackedObjects) {
parentPort.postMessage("numbersMatch");
}
else {
parentPort.postMessage("numbersDoNotMatch");
}
}
});
history.on("end", function(commits) {
// Test should not get this far
parentPort.postMessage("failure");
});
history.on("error", function(err) {
assert.ok(false);
});
history.start();
return promisify(setTimeout)(50000);
}).catch(() => parentPort.postMessage("failure"));