[7.7] [kbn/optimizer] remove disconnect listener (#67161) (#67185)

This commit is contained in:
Spencer 2020-05-21 11:58:50 -07:00 committed by GitHub
parent 206355b739
commit a1c7cf1aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 36 deletions

View file

@ -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,

View file

@ -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