Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2d812ee

Browse files
committedMay 6, 2024··
debug hanging smoke test
1 parent ce966cb commit 2d812ee

File tree

5 files changed

+75
-57
lines changed

5 files changed

+75
-57
lines changed
 

‎smoke-tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"tap": {
3838
"no-coverage": true,
39-
"timeout": 1200,
39+
"timeout": 600,
4040
"jobs": 1,
4141
"test-ignore": "fixtures/*",
4242
"nyc-arg": [

‎smoke-tests/test/fixtures/setup.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy
158158
log(`${spawnCmd} ${spawnArgs.join(' ')}`)
159159
log('-'.repeat(40))
160160

161-
const { stderr, stdout } = await spawn(spawnCmd, spawnArgs, {
161+
const p = spawn(spawnCmd, spawnArgs, {
162162
cwd,
163163
env: {
164164
...getEnvPath(),
@@ -169,10 +169,20 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy
169169
...opts,
170170
})
171171

172-
log(stderr)
173-
log('-'.repeat(40))
174-
log(stdout)
175-
log('='.repeat(40))
172+
// In debug mode, stream stdout and stderr to console so we can debug hanging processes
173+
if (debug) {
174+
p.process.stdout.on('data', (c) => log('STDOUT: ' + c.toString().trim()))
175+
p.process.stderr.on('data', (c) => log('STDERR: ' + c.toString().trim()))
176+
}
177+
178+
const { stdout, stderr } = await p
179+
// If not in debug mode, print full stderr and stdout contents separately
180+
if (!debug) {
181+
log(stderr)
182+
log('-'.repeat(40))
183+
log(stdout)
184+
log('='.repeat(40))
185+
}
176186

177187
return { stderr, stdout }
178188
}

‎smoke-tests/test/npm-replace-global.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ t.test('publish and replace global self', async t => {
125125
await npmPackage({
126126
manifest: { packuments: [publishedPackument] },
127127
tarballs: { [version]: tarball },
128-
times: 2,
128+
times: 3,
129129
})
130130
await fs.rm(cache, { recursive: true, force: true })
131131
await useNpm('install', 'npm@latest', '--global')

‎workspaces/arborist/lib/arborist/index.js

+1-50
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,10 @@ const { homedir } = require('os')
3131
const { depth } = require('treeverse')
3232
const mapWorkspaces = require('@npmcli/map-workspaces')
3333
const { log, time } = require('proc-log')
34-
3534
const { saveTypeMap } = require('../add-rm-pkg-deps.js')
3635
const AuditReport = require('../audit-report.js')
3736
const relpath = require('../relpath.js')
38-
const { LRUCache } = require('lru-cache')
39-
40-
class PackumentCache extends LRUCache {
41-
static #heapLimit = require('node:v8').getHeapStatistics().heap_size_limit
42-
43-
#sizeKey
44-
#disposed = new Set()
45-
46-
#log (...args) {
47-
// It's all silly
48-
log.silly('packumentCache', ...args)
49-
}
50-
51-
constructor ({ heapFactor = 0.25, maxEntryFactor = 0.5, sizeKey = '_contentLength' } = {}) {
52-
const maxSize = Math.floor(PackumentCache.#heapLimit * heapFactor)
53-
const maxEntrySize = maxSize * maxEntryFactor
54-
super({
55-
maxSize,
56-
maxEntrySize,
57-
// Don't cache if we dont know the size
58-
sizeCalculation: (p) => p[sizeKey] || maxEntrySize + 1,
59-
dispose: (v, k) => {
60-
this.#disposed.add(k)
61-
this.#log(k, 'dispose')
62-
},
63-
})
64-
this.#sizeKey = sizeKey
65-
this.#log(`heap:${PackumentCache.#heapLimit} maxSize:${maxSize} maxEntrySize:${maxEntrySize}`)
66-
}
67-
68-
set (k, v, ...args) {
69-
// we use disposed only for a logging signal if we are setting packuments that
70-
// have already been evicted from the cache previously. logging here could help
71-
// us tune this in the future.
72-
const disposed = this.#disposed.has(k)
73-
/* istanbul ignore next - this doesnt happen consistently so hard to test without resorting to unit tests */
74-
if (disposed) {
75-
this.#disposed.delete(k)
76-
}
77-
this.#log(k, 'set', `size:${v[this.#sizeKey]} disposed:${disposed}`)
78-
return super.set(k, v, ...args)
79-
}
80-
81-
has (k, ...args) {
82-
const has = super.has(k, ...args)
83-
this.#log(k, `cache-${has ? 'hit' : 'miss'}`)
84-
return has
85-
}
86-
}
37+
const PackumentCache = require('../packument-cache.js')
8738

8839
const mixins = [
8940
require('../tracker.js'),
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const { LRUCache } = require('lru-cache')
2+
const { getHeapStatistics } = require('node:v8')
3+
const { log } = require('proc-log')
4+
5+
class PackumentCache extends LRUCache {
6+
static #heapLimit = Math.floor(getHeapStatistics().heap_size_limit)
7+
8+
#sizeKey
9+
#disposed = new Set()
10+
11+
#log (...args) {
12+
log.silly('packumentCache', ...args)
13+
}
14+
15+
constructor ({
16+
heapFactor = 0.25,
17+
maxEntryFactor = 0.5,
18+
sizeKey = '_contentLength',
19+
} = {}) {
20+
const maxSize = Math.floor(PackumentCache.#heapLimit * heapFactor)
21+
const maxEntrySize = Math.floor(maxSize * maxEntryFactor)
22+
super({
23+
maxSize,
24+
maxEntrySize,
25+
// Don't cache if we dont know the size
26+
sizeCalculation: (p) => p[sizeKey] || maxEntrySize + 1,
27+
dispose: (v, k) => {
28+
this.#disposed.add(k)
29+
this.#log(k, 'dispose')
30+
},
31+
})
32+
this.#sizeKey = sizeKey
33+
this.#log(`heap:${PackumentCache.#heapLimit} maxSize:${maxSize} maxEntrySize:${maxEntrySize}`)
34+
}
35+
36+
set (k, v, ...args) {
37+
// we use disposed only for a logging signal if we are setting packuments that
38+
// have already been evicted from the cache previously. logging here could help
39+
// us tune this in the future.
40+
const disposed = this.#disposed.has(k)
41+
/* istanbul ignore next - this doesnt happen consistently so hard to test without resorting to unit tests */
42+
if (disposed) {
43+
this.#disposed.delete(k)
44+
}
45+
this.#log(k, 'set', `size:${v[this.#sizeKey]} disposed:${disposed}`)
46+
return super.set(k, v, ...args)
47+
}
48+
49+
has (k, ...args) {
50+
const has = super.has(k, ...args)
51+
this.#log(k, `cache-${has ? 'hit' : 'miss'}`)
52+
return has
53+
}
54+
}
55+
56+
module.exports = PackumentCache
57+
// module.exports = Map

0 commit comments

Comments
 (0)
Please sign in to comment.