-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TearDownTest is being executed while parallel sub tests are still running #934
Comments
Do you mind running a test and confirming whether this happens with version 1.4.0? |
I've just tried running this test suite on 1.4.0 and the result was the same. |
Thank you, I will have a look. |
This occurs for me with 1.6.1 as well. |
It seems like this could be solved by just using t.Cleanup for both |
t.Cleanup is a Go 1.14 feature, this would need us to update the go.mod to 1.14 and drop support of go 1.13. Not necessarily a bad thing, but needs to be done with intent. Is there an approach that works in 1.13? |
oh I see, well, worst case, we can do a conditional fix for 1.14+ but let me dig into 1.13 code. |
@brackendawson looks like the only option for <=1.13 is to use |
@brackendawson although, Suite.SetT also got me thinking - is Suite even concurrent-safe? Because it is being run from multiple routines here, and if there are multiple parallel tests within a suite, they will overwrite each other's |
So on the original bug, I'm thinking we could:
That should stop us from calling teardowns early, do you agree? The |
Nice, yeah I think that works. |
Never mind, spoke too soon, it leads to a deadlock because parallel sub-tests wait for parent test to complete, and parent test won't complete if its waiting for child tests to be done. I'll dig further, however: if parallel tests can't be run, this becomes a moot point. I'd rather document that
Yep, same, there has been some discussion in #187 on this very topic which covers what we talked about here. I suspect this will require a breaking change in the API. I'll do some more digging on this as well. |
That might be best, what a gnarly issue.
I think you're right, perhaps we can come up with a workable design that supports parallel testing for v2.0? Though I must admit I never actually use suite. |
Fwiw, here's a couple of possible fixes for the tearDown ordering:
Although, as mentioned, I think we should just close this ticket and document that parallel testing is not supported for now. |
I imagine the easiest way is to allow test sub-methods to have a signature like so:
and move |
Alright, master...maroux:suite_copy also shows a possible implementation for concurrency-safe suite. |
Any solution? It still doesn't work properly. |
Covered by testifylint#suite-broken-parallel 👌 |
#1109 shows how suite can be made to support parallel tests. As this is a breaking change, there is no plan to merge it into this testify. We are maintaining the repo at v1 only. I do not see a good way of fixing this without the breaking change. Those who wish to use suite and parallel tests should use a fork including the work in #1109. Those who wish to use suite from this repository should not use parallel tests. Suite does not support parallel tests. |
Consider the following example:
After executing that you would get an output similar to this:
Live example: https://play.golang.com/p/fPY3DZFNNok
It is clear that TearDownTest is being executed before all parallel sub tests finish. I see that a similar issue was addressed in #799 and #466 but not resolved in its entirety.
The version in use is 1.5.1
The text was updated successfully, but these errors were encountered: