Files
orca/src/shared/linux-proc-socket-owner-scanner.test.ts
T
NeilandOrca 879aad7dd6 oom(foundation): bound shared readers/limits + add BoundedMap primitive (#10299)
* oom(01): A1-shared-readers — reintroduce #10179 subset

Files: 18 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(02): A2-shared-image-media — reintroduce #10179 subset

Files: 7 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(03): A3-shared-fs-listing — reintroduce #10179 subset

Files: 21 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(04): A4-shared-remote-relay — reintroduce #10179 subset

Files: 8 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(05): A5-shared-misc — reintroduce #10179 subset

Files: 28 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(06): B-shared-wiring — reintroduce #10179 subset

Files: 81 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-24 21:36:57 -07:00

60 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { mapLinuxSocketInodesToPids } from './linux-proc-socket-owner-scanner'
async function* names(values: readonly string[]): AsyncGenerator<string> {
yield* values
}
describe('mapLinuxSocketInodesToPids', () => {
it('streams process and descriptor directories while preserving owner resolution', async () => {
const visitedDirectories: string[] = []
const result = await mapLinuxSocketInodesToPids(new Set([101, 202]), {
readDirectoryNames: (directoryPath) => {
visitedDirectories.push(directoryPath)
if (directoryPath === '/proc') {
return names(['self', '41', '42'])
}
return names(directoryPath.endsWith('/41/fd') ? ['1', '2'] : ['3'])
},
readLink: async (filePath) => {
if (filePath.endsWith('/41/fd/1')) {
return 'socket:[101]'
}
if (filePath.endsWith('/42/fd/3')) {
return 'socket:[202]'
}
return 'pipe:[9]'
}
})
expect(result).toEqual(
new Map([
[101, 41],
[202, 42]
])
)
expect(visitedDirectories).toEqual(['/proc', '/proc/41/fd', '/proc/42/fd'])
})
it('does not retain an arbitrarily large process-name listing', async () => {
let yielded = 0
const result = await mapLinuxSocketInodesToPids(new Set([7]), {
readDirectoryNames: (directoryPath) => {
if (directoryPath !== '/proc') {
return names([])
}
return (async function* () {
for (let pid = 1; pid <= 20_000; pid += 1) {
yielded += 1
yield String(pid)
}
})()
},
readLink: async () => 'socket:[7]'
})
expect(yielded).toBe(20_000)
expect(result.size).toBe(0)
})
})