denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.44k stars 5.37k forks source link

test runner runs a test multiple times #20989

Open aricart opened 1 year ago

aricart commented 1 year ago

I recently split multiple tests from a single file into different ones in order to speed up my tests. I noticed that my brand new Mac Studio ultra was only slightly faster than my aging iMac Pro of 2017. Since tests in a file are not run in parallel, the splitting allows for faster execution.

Now one interesting thing is the name of tests split across the 4 files all start with jetstream -.

Running tests like this:

> deno test -r -A  --filter "jetstream - term reason"
Check file:///Users/aricart/src/github.com/nats-io/nats.deno/jetstream/tests/consumeropts_test.ts
Check file:///Users/aricart/src/github.com/nats-io/nats.deno/jetstream/tests/consumers_test.ts
...
running 1 test from ./jetstream/tests/jetstream_fetchconsumer_test.ts
jetstream - term reason ... ok (131ms)
running 1 test from ./jetstream/tests/jetstream_pullconsumer_test.ts
jetstream - term reason ... ok (131ms)
running 1 test from ./jetstream/tests/jetstream_pushconsumer_test.ts
jetstream - term reason ... ok (129ms)
running 1 test from ./jetstream/tests/jetstream_test.ts
jetstream - term reason ... ok (130ms)

ok | 4 passed | 0 failed | 924 filtered out (1s)

The interesting thing is that jetstream - term reason only exists in one file:

 grep "jetstream - term reason" jetstream/tests/*.ts
jetstream/tests/jetstream_test.ts:Deno.test("jetstream - term reason", async () => {

However the test runner is very happy to execute the same test 4 times and report 925 tests (that number is inflated)

This is in

deno 1.37.2 (release, aarch64-apple-darwin) v8 11.8.172.13 typescript 5.2.2

But is also reproducible on 1.36.4

aricart commented 1 year ago

Not sure if there's some cache issue. But blowing up the cache didn't seem to have an effect.

nayeemrmn commented 1 year ago

Are the test modules importing from each other? I think that can cause this.

aricart commented 1 year ago

Yes there's a common function there