Skip to content

Commit 33e2d1d

Browse files
committed
fix flaky debug-logs test
Total luxury problem. There are too many cores on my laptop, so commands kick off and complete too quickly, resulting in not properly demonstrating the behavior that this test is looking for.
1 parent 39538b4 commit 33e2d1d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Diff for: test/tap/debug-logs.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,28 @@ test('example', function (t) {
6666
t.matches(path.relative(cachedir, logfile), /^_logs/, 'debug log is inside the cache in _logs')
6767
}
6868

69-
// we run a bunch concurrently, this will actually create > than our limit as the check is done
70-
// when the command starts
71-
var todo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
69+
// we run a bunch concurrently, this will actually create > than our limit
70+
// as the check is done when the command starts
71+
//
72+
// It has to be > the log count (10) but also significantly higher than
73+
// the number of cores on the machine, or else some might be able to get
74+
// to the log folder pruning logic in parallel, resulting in FEWER files
75+
// than we expect being present at the end.
76+
var procCount = Math.max(require('os').cpus().length * 2, 12)
77+
var todo = new Array(procCount).join(',').split(',').map((v, k) => k)
7278
asyncMap(todo, function (num, next) {
79+
// another way would be to just simulate this?
80+
// var f = path.join(cachedir, '_logs', num + '-debug.log')
81+
// require('fs').writeFile(f, 'log ' + num, next)
7382
common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) {
7483
if (err) throw err
7584
t.is(code, 1, 'run #' + num + ' errored as expected')
7685
next()
7786
})
7887
}, function () {
88+
var files = glob.sync(path.join(cachedir, '_logs', '*'))
89+
t.ok(files.length > 10, 'there should be more than 10 log files')
90+
7991
// now we do one more and that should clean up the list
8092
common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) {
8193
if (err) throw err

0 commit comments

Comments
 (0)