testify icon indicating copy to clipboard operation
testify copied to clipboard

Add support for parallel sub-tests and remove `suite.Suite` pseudo-interitance

Open maroux opened this issue 2 years ago • 11 comments

Summary

Add support for parallel sub-tests and remove suite.Suite pseudo-interitance

Changes

  • Run sub-tests in a group so TearDownSuite is called in the right order
  • Remove suite.Suite interface / struct because it's a bad attempt at inheritance which is causing problems.

Motivation

Currently, parallel sub-tests are broken with suite. Go runs parallel tests by deferring them until the end of parent test. testing.T.Run returns early, and thus the deferred calls in suite fire off, such as TearDownSuite (the test itself runs in a separate go-routine).

Additionally, since there's only one T object per suite instance, this means during parallel tests, this object gets overridden by subsequent tests's F method, which leads to test output being associated with the wrong test, and potentially other problems because testing.T is NOT concurrent-safe.

Example usage (if applicable)

type ExampleTestSuite struct {}

func (suite *ExampleTestSuite) TestExample(t *suite.T) {
    t.Equal(5, 5)
}

Related issues

Fixes #934, #187.

maroux avatar Aug 04 '21 05:08 maroux

Thanks for this,

Additionally, since there's only one T object per suite instance, this means during parallel tests, this object gets overridden by subsequent tests's F method, which leads to test output being associated with the wrong test, and potentially other problems because testing.T is NOT concurrent-safe.

is the main fix I'm looking forward to.

ivanpk avatar Dec 10 '21 20:12 ivanpk

I can see that this is tagged with the v1.7.0 milestone, is this likely to be merged before v2 at this stage?

Really keen on being able to run parallel tests within suites.

nightah avatar May 12 '22 23:05 nightah

is this likely to be merged before v2 at this stage?

No. Given that this is a breaking change.

maroux avatar May 13 '22 01:05 maroux

Great PR! Looking forward to it :)

LorisFriedel avatar Jul 07 '22 06:07 LorisFriedel

Any progress? :eyes:

FedorLap2006 avatar Aug 26 '22 22:08 FedorLap2006

Any progress on this?

mstrYoda avatar Mar 09 '23 14:03 mstrYoda

v2 will not happen.

Please publish this as a separate module that YOU will maintain.

dolmen avatar Jul 25 '23 04:07 dolmen

@dolmen have there been any public post about v2 not happening?

pmenglund avatar Jul 25 '23 14:07 pmenglund

@pmenglund Have there been any public post about v2 happening?

The fact is that maintaining v1 is a huge effort. Just look at the count of open issues and PRs. Nobody is paid to work on this project. I'm currently doing a massive triage, but I keep seeing new issues and PRs coming almost every day. And maintainers ressources are scarce. The API surface continues to grow with PRs, but most contributors are gone once their feature is merged.

v2 will magically make v1 disappear. v2 will just make maintenance harder because both v1 and v2 will have to be maintained by the same people.

Packages assert/require/mock v1 are good enough for most people. Also I know that most projects which use v1 will never move away from v1: who wants to take the risk of breaking their test suite for no benefits?

I'm also seeing right now the consequences of PRs having been merged without the care needed for such a popular project (for example, public APIs introduced in recent patch releases. Also API surface being increase with badly designed APIs).

So if someone wants to make a v2 with APIs cleanup, just use a separate module path.

dolmen avatar Jul 25 '23 22:07 dolmen

@dolmen there was no critique whatsoever in my question, I know what it takes to run an open source project in your spare time. I was just curious if I had missed some announcement since the README still says "We are working on testify v2 ..."

pmenglund avatar Jul 25 '23 23:07 pmenglund

@pmenglund Thanks for the pointer. I will propose something to change the paragraph.

dolmen avatar Jul 26 '23 06:07 dolmen