Skip to content

Commit d9f833c

Browse files
committed
Add timeout to test
1 parent db514a9 commit d9f833c

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

library/sources/HTTPServer.stats.test.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -235,46 +235,48 @@ t.test("it tracks spoofed bots", async () => {
235235

236236
await new Promise<void>((resolve) => {
237237
server.listen(3330, () => {
238-
Promise.all([
239-
fetch({
240-
url: new URL("http://localhost:3330/test"),
241-
method: "GET",
242-
headers: {
243-
"x-forwarded-for": "1.2.3.4",
244-
"user-agent": "Googlebot/2.1 (+http://www.google.com/bot.html)",
245-
},
246-
timeoutInMS: 500,
247-
}),
248-
fetch({
249-
url: new URL("http://localhost:3330/test"),
250-
method: "GET",
251-
headers: {
252-
"x-forwarded-for": "5.6.7.8",
253-
"user-agent": "GoogleBot/2.1 (+http://www.google.com/bot.html)",
254-
},
255-
timeoutInMS: 500,
256-
}),
257-
]).then(([response1, response2]) => {
258-
t.equal(response1.statusCode, 403);
259-
t.equal(response2.statusCode, 403);
260-
const stats = agent.getInspectionStatistics().getStats();
261-
t.same(stats.userAgents, {
262-
breakdown: {},
263-
});
264-
t.same(stats.ipAddresses, {
265-
breakdown: {
266-
"known_threat_actors/public_scanners": 1,
267-
},
238+
setTimeout(() => {
239+
Promise.all([
240+
fetch({
241+
url: new URL("http://localhost:3330/test"),
242+
method: "GET",
243+
headers: {
244+
"x-forwarded-for": "1.2.3.4",
245+
"user-agent": "Googlebot/2.1 (+http://www.google.com/bot.html)",
246+
},
247+
timeoutInMS: 500,
248+
}),
249+
fetch({
250+
url: new URL("http://localhost:3330/test"),
251+
method: "GET",
252+
headers: {
253+
"x-forwarded-for": "5.6.7.8",
254+
"user-agent": "GoogleBot/2.1 (+http://www.google.com/bot.html)",
255+
},
256+
timeoutInMS: 500,
257+
}),
258+
]).then(([response1, response2]) => {
259+
t.equal(response1.statusCode, 403);
260+
t.equal(response2.statusCode, 403);
261+
const stats = agent.getInspectionStatistics().getStats();
262+
t.same(stats.userAgents, {
263+
breakdown: {},
264+
});
265+
t.same(stats.ipAddresses, {
266+
breakdown: {
267+
"known_threat_actors/public_scanners": 1,
268+
},
269+
});
270+
t.same(stats.botSpoofing, {
271+
breakdown: {
272+
// eslint-disable-next-line camelcase
273+
google_test: 2,
274+
},
275+
});
276+
server.close();
277+
resolve();
268278
});
269-
t.same(stats.botSpoofing, {
270-
breakdown: {
271-
// eslint-disable-next-line camelcase
272-
google_test: 2,
273-
},
274-
});
275-
server.close();
276-
resolve();
277-
});
279+
}, 500);
278280
});
279281
});
280282
});

0 commit comments

Comments
 (0)