fix: address cleanup review lifecycle and connection settings
This commit is contained in:
parent
512f2f1c32
commit
9d3e1a7bb9
11 changed files with 264 additions and 17 deletions
|
|
@ -94,3 +94,54 @@ test('successful initialization clears timeout handles immediately', async () =>
|
|||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
|
||||
test('reusing a manager after shutdown closes each new connection lifetime once', async () => {
|
||||
const connect = mock(async () => {}),
|
||||
disconnect = mock(async () => {});
|
||||
const c = container({ cache: { connect, disconnect } });
|
||||
const manager = new ServiceLifecycleManager();
|
||||
await manager.initializeServices(c);
|
||||
await manager.shutdownServices(c);
|
||||
await manager.shutdownServices(c);
|
||||
await manager.initializeServices(c);
|
||||
await manager.shutdownServices(c);
|
||||
expect(connect).toHaveBeenCalledTimes(2);
|
||||
expect(disconnect).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test('hung rollback does not hide or indefinitely delay the original startup failure', async () => {
|
||||
const pending = deferred();
|
||||
const failure = new Error('startup failed');
|
||||
const disconnect = mock(() => pending.promise);
|
||||
const c = container({
|
||||
cache: { connect: async () => {}, disconnect },
|
||||
mongoClient: {
|
||||
connect: async () => {
|
||||
throw failure;
|
||||
},
|
||||
},
|
||||
});
|
||||
const manager = new ServiceLifecycleManager();
|
||||
try {
|
||||
await expect(manager.initializeServices(c, 5)).rejects.toBe(failure);
|
||||
expect(disconnect).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
pending.resolve();
|
||||
}
|
||||
await manager.shutdownServices(c);
|
||||
expect(disconnect).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('a retry cannot overlap an earlier unresolved initializer after a timeout', async () => {
|
||||
const pending = deferred();
|
||||
const connect = mock(() => pending.promise),
|
||||
disconnect = mock(async () => {});
|
||||
const c = container({ cache: { connect, disconnect } });
|
||||
const manager = new ServiceLifecycleManager();
|
||||
await expect(manager.initializeServices(c, 5)).rejects.toThrow('timed out');
|
||||
await expect(manager.initializeServices(c, 5)).rejects.toThrow('already in progress');
|
||||
expect(connect).toHaveBeenCalledTimes(1);
|
||||
pending.resolve();
|
||||
await Bun.sleep(0);
|
||||
expect(disconnect).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue