FxTS icon indicating copy to clipboard operation
FxTS copied to clipboard

`npm run test` failed intermittently due to timeout

Open ppeeou opened this issue 3 years ago • 4 comments

Bug Report

💻 Code

npm run test failed intermittently due to timeout.

image

🙁 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

ppeeou avatar Dec 16 '21 02:12 ppeeou

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

ppeeou avatar Dec 20 '21 07:12 ppeeou

In the past, the case of failure because it took a long time does not occur, but other cases are occurring image

ppeeou avatar Dec 22 '21 05:12 ppeeou

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);
};

ppeeou avatar Dec 31 '21 16:12 ppeeou

All tests must be passed, but some tests fail depending on the environment. Of course, maxWorkers is 1.

image

      × 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

sunrabbit123 avatar Mar 24 '22 05:03 sunrabbit123