Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrutter committed Feb 7, 2025
1 parent e68d31a commit 7e3f7c5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {EventEmitter} from 'node:events';
import {PassThrough as PassThroughStream} from 'node:stream';
import type {Socket} from 'node:net';
import http from 'node:http';
import https from 'node:https';
import test from 'ava';
import is from '@sindresorhus/is';
import type {Handler} from 'express';
Expand All @@ -21,8 +22,13 @@ const handler413: Handler = (_request, response) => {
response.end();
};

const createSocketTimeoutStream = (): http.ClientRequest => {
return http.request("http://example.com", {
const createSocketTimeoutStream = (url): http.ClientRequest => {
if (url.indexOf("https:") > -1) {
return https.request(url, {
timeout: 1
});
}
return http.request(url, {
timeout: socketTimeout
});
};
Expand All @@ -48,7 +54,7 @@ test('works on timeout', withServer, async (t, server, got) => {
}

knocks++;
return createSocketTimeoutStream();
return createSocketTimeoutStream(server.url);
},
})).body, 'who`s there?');
});
Expand Down Expand Up @@ -84,7 +90,7 @@ test('setting to `0` disables retrying', async t => {
return 0;
},
},
request: () => createSocketTimeoutStream(),
request: () => createSocketTimeoutStream("https://example.com"),
}), {
instanceOf: TimeoutError,
message: `Timeout awaiting 'socket' for ${socketTimeout}ms`,
Expand Down

0 comments on commit 7e3f7c5

Please sign in to comment.