fix(code-runtime): support SEA startup and immediate control writes
This commit is contained in:
1 parent
98d3af0683
commit
7f5eb6db9a
19 files changed
+145
-49
No files matched your search
@@ -124,7 +124,7 @@ it('ignores callbacks already captured by an emission when an earlier listener c
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects queued writes if the owner closes before they start', async () => {
|
||||
it('rejects pending write receipts when the owner closes', async () => {
|
||||
const { a } = pair()
|
||||
const channel = new JsonChannel(a, 64, () => {}, () => {})
|
||||
const pending = channel.send({ n: 1 })
|
||||
@@ -138,8 +138,10 @@ it('bounds queued frames while a receiver is not reading', async () => {
|
||||
const channel = new JsonChannel(stream, 32, () => {}, () => {})
|
||||
const pending = channel.send({ value: '1234567890' })
|
||||
await expect(channel.send({ value: '1234567890' })).rejects.toThrow('queued bytes')
|
||||
const draining = channel.drain()
|
||||
channel.close()
|
||||
await expect(pending).rejects.toThrow('closed')
|
||||
await draining
|
||||
})
|
||||
|
||||
it.each(['error', 'close'])('settles a blocked write when the stream emits %s', async (event) => {
|
||||
@@ -154,3 +156,11 @@ it.each(['error', 'close'])('settles a blocked write when the stream emits %s',
|
||||
if (event === 'error') expect(failure?.message).toBe('transport failed')
|
||||
channel.close()
|
||||
})
|
||||
|
||||
|
||||
it.each([new Error('write failed'), 'write failed'])('rejects a synchronous transport write failure: %s', async (failure) => {
|
||||
const stream = new Duplex({ read() {}, write() { throw failure } })
|
||||
const channel = new JsonChannel(stream, 64, () => {}, () => {})
|
||||
onTestFinished(() => { channel.close() })
|
||||
await expect(channel.send({ value: 1 })).rejects.toThrow('write failed')
|
||||
})
|
||||
@@ -439,8 +439,9 @@ describe('Node runtime host failures', () => {
|
||||
const spec = h.spawn.mock.calls[0]?.[0]
|
||||
expect(spec?.env?.DSH_CODE_RUNTIME_NODE).toBe('1')
|
||||
expect(Object.hasOwn(spec?.env ?? {}, 'PATH')).toBe(false)
|
||||
expect(spec?.argv.at(-1)).toBe('134217728')
|
||||
expect(Object.entries(spec?.env ?? {}).filter(([, value]) => value !== undefined)).toEqual([['DSH_CODE_RUNTIME_NODE', '1']])
|
||||
expect(spec?.argv).toEqual([process.execPath, '134217728'])
|
||||
expect(Object.fromEntries(Object.entries(spec?.env ?? {}).filter(([, value]) => value !== undefined)))
|
||||
.toEqual({ DSH_CODE_RUNTIME_NODE: '1', NODE_OPTIONS: '--max-old-space-size=512' })
|
||||
} finally {
|
||||
if (prior === undefined) Reflect.deleteProperty(process, 'pkg')
|
||||
else Object.defineProperty(process, 'pkg', prior)
|
||||
|
||||
@@ -100,6 +100,13 @@ describe('Node program process', () => {
|
||||
expect((await run({ program, bindings: [] })).error?.kind).toBe('timeout')
|
||||
})
|
||||
|
||||
it('retains console output emitted immediately before a non-yielding program', async () => {
|
||||
const { run } = await setup({ timeoutMs: 1000, graceMs: 50 })
|
||||
const result = await run({ program: 'console.log("before hot loop"); for (;;) {}', bindings: [] })
|
||||
expect(result.error?.kind).toBe('timeout')
|
||||
expect(result.logs).toEqual(['before hot loop'])
|
||||
})
|
||||
|
||||
it('does not pause the deadline while a binding is pending', async () => {
|
||||
const { run } = await setup({ timeoutMs: 1000, graceMs: 50 })
|
||||
const result = await run({ program: 'void tools.wait({}); for (;;) {}', bindings: bindings({ wait: () => new Promise(() => {}) }) })
|
||||
|
||||
Reference in new issue
Block a user