FxTS
FxTS copied to clipboard
`npm run test` failed intermittently due to timeout
Bug Report
💻 Code
npm run test
failed intermittently due to timeout.
🙁 Actual behavior
The setTimeout
set in test does not match intermittently.
🙂 Expected behavior
The test action should always succeed.
Version Infomation
- Operating system:
- Typescript:
- Nodejs: 16.3.0
We do a lot of testing asynchronous operations, and we want them to work as we intended by the correct time.
our test can fail if jest run test in parallel. execution environment
- branch: feature/jest-dockerenv
docker run --cpus 2 --rm -v `PWD`:/app --name fxts -it fxts:0.1 bash
npm test
No failure with jest maxWorkers set to 1 https://jestjs.io/docs/cli#--maxworkersnumstring
In the past, the case of failure because it took a long time does not occur, but other cases are occurring
https://jestjs.io/docs/timer-mocks
Timer Mocks The native timer functions (i.e., setTimeout, setInterval, clearTimeout, clearInterval) are less than ideal for a testing environment since they depend on real time to elapse. Jest can swap out timers with functions that allow you to control the passage of time. Great Scott!
We measure maximum and minimum times to measure time.
However, we are using setTimeout
for the minimum time, but setTimeout
does not seem to be suitable as a test.
https://github.com/marpple/FxTS/blob/main/test/utils.ts#L3-L5
export const callFuncAfterTime = (callback: Arrow, time = 1000) => {
setTimeout(callback, time);
};
All tests must be passed, but some tests fail depending on the environment. Of course, maxWorkers is 1.
× should be chunked after concurrent (655 ms) // around 650ms
× should be chunked after concurrent with filter (1055 ms) // around 1050ms
× should be chunked before concurrent (1058 ms) // around 1050ms
Shouldn't we lower the hurdles?
Version Infomation
Operating system: windows11 Typescript: Nodejs: 16.13.2