T-16: M0.1b — Make repo-wide bun test green: fix queue, shutdown-signal and research-workflow test failures
This commit is contained in:
parent
890761e0d5
commit
9c4e87cdfd
17 changed files with 366 additions and 266 deletions
|
|
@ -5,14 +5,14 @@ describe('Shutdown', () => {
|
|||
let shutdown: Shutdown;
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset singleton instance for each test
|
||||
(Shutdown as any).instance = null;
|
||||
shutdown = Shutdown.getInstance({ timeout: 1000 });
|
||||
// Reset singleton instance and remove any prior signal listeners
|
||||
Shutdown.reset();
|
||||
shutdown = Shutdown.getInstance({ timeout: 1000, autoRegister: false });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Clean up
|
||||
(Shutdown as any).instance = null;
|
||||
// Clean up listeners and singleton
|
||||
Shutdown.reset();
|
||||
});
|
||||
|
||||
describe('getInstance', () => {
|
||||
|
|
@ -24,7 +24,8 @@ describe('Shutdown', () => {
|
|||
});
|
||||
|
||||
it('should use provided config on first call', () => {
|
||||
const instance = Shutdown.getInstance({ timeout: 5000 });
|
||||
Shutdown.reset();
|
||||
const instance = Shutdown.getInstance({ timeout: 5000, autoRegister: false });
|
||||
expect(instance).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -125,20 +126,28 @@ describe('Shutdown', () => {
|
|||
});
|
||||
|
||||
it('should respect timeout', async () => {
|
||||
let slowTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const slowHandler = mock(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
await new Promise(resolve => {
|
||||
slowTimer = setTimeout(resolve, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
shutdown = Shutdown.getInstance({ timeout: 100 });
|
||||
Shutdown.reset();
|
||||
shutdown = Shutdown.getInstance({ timeout: 100, autoRegister: false });
|
||||
shutdown.onShutdown(slowHandler, 10, 'Slow Handler');
|
||||
|
||||
const start = Date.now();
|
||||
await expect(shutdown.shutdown()).rejects.toThrow('Shutdown timeout');
|
||||
try {
|
||||
await expect(shutdown.shutdown()).rejects.toThrow('Shutdown timeout');
|
||||
} finally {
|
||||
clearTimeout(slowTimer);
|
||||
}
|
||||
const duration = Date.now() - start;
|
||||
|
||||
// Shutdown waits for timeout (100ms) plus some processing time
|
||||
expect(duration).toBeGreaterThan(90);
|
||||
expect(duration).toBeLessThan(1500); // But not the full 2000ms
|
||||
expect(duration).toBeLessThan(500);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -161,8 +170,8 @@ describe('Shutdown', () => {
|
|||
await shutdown.shutdown();
|
||||
|
||||
// Reset by creating new instance
|
||||
(Shutdown as any).instance = null;
|
||||
shutdown = Shutdown.getInstance({ timeout: 1000 });
|
||||
Shutdown.reset();
|
||||
shutdown = Shutdown.getInstance({ timeout: 1000, autoRegister: false });
|
||||
|
||||
shutdown.onShutdown(handler, 10, 'Handler');
|
||||
await shutdown.shutdown();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue