Skip to content

Commit 0a67f36

Browse files
committed
Fixed type error
1 parent 4d0990f commit 0a67f36

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

tests/performance.test.ts

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
import { test, expect } from "bun:test";
22
import app from "../src/controllers/unit-tests";
33
import {
4-
runUnitTestResponseSchema,
5-
type RunUnitTestRequest,
6-
type RunUnitTestResponse,
4+
runUnitTestResponseSchema,
5+
type RunUnitTestRequest,
6+
type RunUnitTestResponse,
77
} from "../src/lib/validation";
88

99
test("App handles 20 concurrent requests - sorting big arrays", async () => {
10-
const mockUserCode = await Bun.file(
11-
__dirname + "/data/mock-performance-code.py",
12-
).text();
13-
const mockUnitTests = await Bun.file(
14-
__dirname + "/data/mock-performance-tests.py",
15-
).text();
10+
const mockUserCode = await Bun.file(
11+
__dirname + "/data/mock-performance-code.py",
12+
).text();
13+
const mockUnitTests = await Bun.file(
14+
__dirname + "/data/mock-performance-tests.py",
15+
).text();
1616

17-
const payload: RunUnitTestRequest = {
18-
api_key: process?.env?.API_KEY || "",
19-
user_code: mockUserCode,
20-
unit_tests: mockUnitTests,
21-
};
17+
const payload: RunUnitTestRequest = {
18+
api_key: process?.env?.API_KEY || "",
19+
user_code: mockUserCode,
20+
unit_tests: mockUnitTests,
21+
};
2222

23-
const promises = [];
24-
for (let i = 0; i < 20; i++) {
25-
promises.push(
26-
app.request("/", {
27-
method: "POST",
28-
body: JSON.stringify(payload),
29-
}),
30-
);
31-
}
32-
const start = Date.now();
33-
const finishedPromises = await Promise.all(promises);
34-
const end = Date.now();
35-
for (const result of finishedPromises) {
36-
expect(result.status).toBe(200);
37-
const returned: RunUnitTestResponse = await result.json();
38-
runUnitTestResponseSchema.parse(returned);
23+
const promises: Promise<Response>[] = [];
24+
for (let i = 0; i < 20; i++) {
25+
const req = app.request("/", {
26+
method: "POST",
27+
body: JSON.stringify(payload),
28+
});
29+
promises.push(req as Promise<Response>);
30+
}
31+
const start = Date.now();
32+
const finishedPromises = await Promise.all(promises);
33+
const end = Date.now();
34+
for (const result of finishedPromises) {
35+
expect(result.status).toBe(200);
36+
const returned: RunUnitTestResponse = await result.json();
37+
runUnitTestResponseSchema.parse(returned);
3938

40-
const { total_points, max_total_points } =
41-
returned!.runalyzer_output!.test_result;
42-
expect(total_points).toBe(max_total_points);
43-
}
44-
console.log(`Time taken: ${end - start}ms`);
45-
expect(end - start).toBeLessThan(5000);
39+
const { total_points, max_total_points } =
40+
returned!.runalyzer_output!.test_result;
41+
expect(total_points).toBe(max_total_points);
42+
}
43+
console.log(`Time taken: ${end - start}ms`);
44+
expect(end - start).toBeLessThan(5000);
4645
});

0 commit comments

Comments
 (0)