|
1 | 1 | import { test, expect } from "bun:test"; |
2 | 2 | import app from "../src/controllers/unit-tests"; |
3 | 3 | import { |
4 | | - runUnitTestResponseSchema, |
5 | | - type RunUnitTestRequest, |
6 | | - type RunUnitTestResponse, |
| 4 | + runUnitTestResponseSchema, |
| 5 | + type RunUnitTestRequest, |
| 6 | + type RunUnitTestResponse, |
7 | 7 | } from "../src/lib/validation"; |
8 | 8 |
|
9 | 9 | 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(); |
16 | 16 |
|
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 | + }; |
22 | 22 |
|
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); |
39 | 38 |
|
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); |
46 | 45 | }); |
0 commit comments