Skip to content

Commit 5bfeef8

Browse files
committed
Fix test timeouts
1 parent d92a0cb commit 5bfeef8

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

src/cse-machine/__tests__/cse-machine-errors.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { expect, test } from 'vitest'
22
import { Chapter, Variant } from '../../langs'
33
import { stripIndent } from '../../utils/formatters'
44
import {
5-
expectParsedError,
65
expectFinishedResult,
6+
expectParsedError,
77
testFailure,
88
testSuccess
99
} from '../../utils/testing'
@@ -168,17 +168,21 @@ test("Builtins don't create additional errors when it's not their fault", () =>
168168
).toEqual('Line 2: Name a not declared.')
169169
})
170170

171-
test('Infinite recursion with a block bodied function', { timeout: 15_000 }, () => {
172-
return expectParsedError(
173-
stripIndent`
171+
test(
172+
'Infinite recursion with a block bodied function',
173+
{ timeout: process.env.GITHUB_ACTIONS ? 30_000 : 15_000 },
174+
() => {
175+
return expectParsedError(
176+
stripIndent`
174177
function i(n) {
175178
return n === 0 ? 0 : 1 + i(n-1);
176179
}
177180
i(300000);
178181
`,
179-
optionEC4
180-
).toEqual(expect.stringMatching(/Maximum call stack size exceeded\n *(i\(\d*\)[^i]{2,4}){3}/))
181-
})
182+
optionEC4
183+
).toEqual(expect.stringMatching(/Maximum call stack size exceeded\n *(i\(\d*\)[^i]{2,4}){3}/))
184+
}
185+
)
182186

183187
test(
184188
'Infinite recursion with function calls in argument',

src/cse-machine/__tests__/cse-machine-unique-id.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { expect, test } from 'vitest'
2-
import { mockContext } from '../../utils/testing/mocks'
3-
import type { Context, Environment } from '../../types'
42
import { Chapter } from '../../langs'
5-
import { stripIndent } from '../../utils/formatters'
63
import { runCodeInSource } from '../../runner'
4+
import type { Context, Environment } from '../../types'
5+
import { stripIndent } from '../../utils/formatters'
6+
import { mockContext } from '../../utils/testing/mocks'
77
import { createProgramEnvironment } from '../utils'
88

99
const getContextFrom = async (code: string, envSteps?: number) => {
@@ -91,7 +91,7 @@ const getProgramEnv = (context: Context) => {
9191

9292
test(
9393
'Program environment id stays the same regardless of amount of steps',
94-
{ timeout: 10_000 },
94+
{ timeout: process.env.GITHUB_ACTIOS ? 20_000 : 10_000 },
9595
async () => {
9696
const code = stripIndent`
9797
let x = 0;

src/runner/__tests__/execMethod.test.ts

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { beforeEach, describe, expect, test, vi } from 'vitest'
2-
import runners, { type RunnerTypes } from '../sourceRunner'
3-
import type { ExecutionMethod } from '../../types'
4-
import { Chapter, Variant } from '../../langs'
5-
import type { Runner } from '../types'
62
import { runCodeInSource } from '..'
7-
import { mockContext } from '../../utils/testing/mocks'
8-
import { getChapterName, objectKeys } from '../../utils/misc'
93
import { parseError } from '../..'
10-
import * as validator from '../../validator/validator'
4+
import { Chapter, Variant } from '../../langs'
5+
import type { ExecutionMethod } from '../../types'
6+
import { getChapterName, objectKeys } from '../../utils/misc'
117
import { wrapWithSkipAndOnly } from '../../utils/testing/misc'
8+
import { mockContext } from '../../utils/testing/mocks'
9+
import * as validator from '../../validator/validator'
10+
import runners, { type RunnerTypes } from '../sourceRunner'
11+
import type { Runner } from '../types'
1212

1313
vi.spyOn(validator, 'validateAndAnnotate')
1414

@@ -73,6 +73,7 @@ interface TestCase {
7373
expectedValidate: boolean
7474

7575
verboseErrors?: boolean
76+
timeout?: number
7677
}
7778

7879
const sourceCases: TestCase[] = [
@@ -217,30 +218,37 @@ async function caseTester({
217218
}
218219
}
219220

220-
const testCases = wrapWithSkipAndOnly('describe', function (desc: string, cases: TestCase[]) {
221-
this(desc, () =>
222-
test.each(
223-
cases.map(({ code, verboseErrors, contextMethod, chapter, variant, ...tc }, i) => {
224-
chapter = chapter ?? Chapter.SOURCE_1
225-
variant = variant ?? Variant.DEFAULT
226-
const context = mockContext(chapter, variant)
227-
if (contextMethod !== undefined) {
228-
context.executionMethod = contextMethod
229-
}
230-
231-
const chapterName = getChapterName(chapter)
232-
let desc = `${i + 1}. Testing ${chapterName}, Variant: ${variant}, expected ${tc.expectedRunner} runner`
233-
code = code ?? ''
234-
if (verboseErrors) {
235-
code = `"enable verbose";\n${code}`
236-
desc += ' (verbose errors)'
237-
}
238-
239-
return [desc, { code, chapter, variant, ...tc }]
240-
})
241-
)('%s', async (_, to) => caseTester(to))
242-
)
243-
})
221+
const testCases = wrapWithSkipAndOnly(
222+
'describe',
223+
function (desc: string, cases: TestCase[], timeout?: number) {
224+
this(desc, () => {
225+
const testEach = test.each(
226+
cases.map(({ code, verboseErrors, contextMethod, chapter, variant, ...tc }, i) => {
227+
chapter = chapter ?? Chapter.SOURCE_1
228+
variant = variant ?? Variant.DEFAULT
229+
const context = mockContext(chapter, variant)
230+
if (contextMethod !== undefined) {
231+
context.executionMethod = contextMethod
232+
}
233+
234+
const chapterName = getChapterName(chapter)
235+
let desc = `${i + 1}. Testing ${chapterName}, Variant: ${variant}, expected ${tc.expectedRunner} runner`
236+
code = code ?? ''
237+
if (verboseErrors) {
238+
code = `"enable verbose";\n${code}`
239+
desc += ' (verbose errors)'
240+
}
241+
242+
return [desc, { code, chapter, variant, ...tc }]
243+
})
244+
)
245+
if (timeout !== undefined) {
246+
return testEach('%s', { timeout }, async (_, to) => caseTester(to))
247+
}
248+
return testEach('%s', async (_, to) => caseTester(to))
249+
})
250+
}
251+
)
244252

245253
describe('Ensure that the correct runner is used for the given evaluation context and settings', () => {
246254
testCases('Test regular source cases', sourceCases)
@@ -300,7 +308,8 @@ describe('Ensure that the correct runner is used for the given evaluation contex
300308
)
301309

302310
return [fullCase, verboseErrorCase, ...variantCases]
303-
})
311+
}),
312+
10_000
304313
)
305314

306315
testCases(

0 commit comments

Comments
 (0)