Skip to content

Commit

Permalink
Workaround superagent bug
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Aug 14, 2023
1 parent 0ef4fb7 commit e264670
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/core/server/integration_tests/http/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ describe('KibanaRequest', () => {
// end required to send request
.end();

setTimeout(() => incomingRequest.abort(), 50);
setTimeout(() => {
incomingRequest.abort();

// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
incomingRequest.req.destroyed = false;
// @ts-expect-error
incomingRequest.req.destroy();
}, 50);
await done;
expect(nextSpy).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -227,7 +236,16 @@ describe('KibanaRequest', () => {
// end required to send request
.end();

setTimeout(() => incomingRequest.abort(), 50);
setTimeout(() => {
incomingRequest.abort();

// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
incomingRequest.req.destroyed = false;
// @ts-expect-error
incomingRequest.req.destroy();
}, 50);
await done;
expect(nextSpy).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -366,7 +384,16 @@ describe('KibanaRequest', () => {
.get('/')
// end required to send request
.end();
setTimeout(() => incomingRequest.abort(), 50);
setTimeout(() => {
incomingRequest.abort();

// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
incomingRequest.req.destroyed = false;
// @ts-expect-error
incomingRequest.req.destroy();
}, 50);
await done;
expect(nextSpy).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -401,7 +428,16 @@ describe('KibanaRequest', () => {
.send({ foo: 'bar' })
// end required to send request
.end();
setTimeout(() => incomingRequest.abort(), 50);
setTimeout(() => {
incomingRequest.abort();

// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
incomingRequest.req.destroyed = false;
// @ts-expect-error
incomingRequest.req.destroy();
}, 50);
await done;
expect(nextSpy).toHaveBeenCalledTimes(1);
});
Expand Down
12 changes: 12 additions & 0 deletions src/core/server/integration_tests/metrics/server_collector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ describe('ServerMetricsCollector', () => {
const waitFor1stAbort = disconnectAborted$.pipe(take(1)).toPromise();

discoReq1.abort();
// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
discoReq1.req.destroyed = false;
// @ts-expect-error
discoReq1.req.destroy();

// Wait for the aborted$ event
await waitFor1stAbort;
Expand All @@ -133,6 +139,12 @@ describe('ServerMetricsCollector', () => {
const waitFor2ndAbort = disconnectAborted$.pipe(take(1)).toPromise();

discoReq2.abort();
// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
discoReq2.req.destroyed = false;
// @ts-expect-error
discoReq2.req.destroy();

// Wait for the aborted$ event
await waitFor2ndAbort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ describe('APMEventClient', () => {
}, 100);
});
incomingRequest.abort();

// Hack to resolve superagent's bug https://github.com/ladjs/superagent/pull/1774
// Can be removed once a new version is published and we upgrade.
// @ts-expect-error
incomingRequest.req.destroyed = false;
// @ts-expect-error
incomingRequest.req.destroy();
}, 100);
});

Expand Down

0 comments on commit e264670

Please sign in to comment.