mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
parent
206355b739
commit
a1c7cf1aa6
2 changed files with 17 additions and 36 deletions
|
@ -75,18 +75,6 @@ async function waitForTick() {
|
|||
}
|
||||
|
||||
describe('emits and completes when parent exists because:', () => {
|
||||
test('"disconnect" event', async () => {
|
||||
const mockProc = new MockProcess();
|
||||
const promise = record(observeParentOffline(mockProc, workerMsgs));
|
||||
mockProc.emit('disconnect');
|
||||
expect(await promise).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"next: 'parent offline (disconnect event)'",
|
||||
"complete",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('process.connected is false', async () => {
|
||||
const mockProc = new MockProcess({
|
||||
connected: false,
|
||||
|
|
|
@ -44,35 +44,28 @@ export interface Process extends EventEmitter {
|
|||
* call errored with an 'ERR_IPC_CHANNEL_CLOSED' exception
|
||||
*/
|
||||
export function observeParentOffline(process: Process, workerMsgs: WorkerMsgs) {
|
||||
return Rx.race(
|
||||
Rx.fromEvent(process, 'disconnect').pipe(
|
||||
take(1),
|
||||
map(() => 'parent offline (disconnect event)')
|
||||
),
|
||||
return sleep(5000).pipe(
|
||||
mergeMap(() => {
|
||||
if (!process.connected || !process.send) {
|
||||
return Rx.of('parent offline (disconnected)');
|
||||
}
|
||||
|
||||
sleep(5000).pipe(
|
||||
mergeMap(() => {
|
||||
if (!process.connected || !process.send) {
|
||||
return Rx.of('parent offline (disconnected)');
|
||||
}
|
||||
process.send(workerMsgs.ping());
|
||||
|
||||
process.send(workerMsgs.ping());
|
||||
const pong$ = Rx.fromEvent<[any]>(process, 'message').pipe(
|
||||
first(([msg]) => isParentPong(msg)),
|
||||
map(() => {
|
||||
throw new Error('parent still online');
|
||||
})
|
||||
);
|
||||
|
||||
const pong$ = Rx.fromEvent<[any]>(process, 'message').pipe(
|
||||
first(([msg]) => isParentPong(msg)),
|
||||
map(() => {
|
||||
throw new Error('parent still online');
|
||||
})
|
||||
);
|
||||
// give the parent some time to respond, if the ping
|
||||
// wins the race the parent is considered online
|
||||
const timeout$ = sleep(5000).pipe(map(() => 'parent offline (ping timeout)'));
|
||||
|
||||
// give the parent some time to respond, if the ping
|
||||
// wins the race the parent is considered online
|
||||
const timeout$ = sleep(5000).pipe(map(() => 'parent offline (ping timeout)'));
|
||||
return Rx.race(pong$, timeout$);
|
||||
}),
|
||||
|
||||
return Rx.race(pong$, timeout$);
|
||||
})
|
||||
)
|
||||
).pipe(
|
||||
/**
|
||||
* resubscribe to the source observable (triggering the timer,
|
||||
* ping, wait for response) if the source observable does not
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue