You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Anyone looking at adding synctest support in Ginkgo?
It is really bringing a lot of value when testing asynchronous behaviors and I was wondering if it could be integrated directly in Ginkgo.
I managed to use it in my current test suites, here are the difficulties I faced:
Access to the *testing.T (needed to call synctest.Test). For now I am storing that in a package variable at the beginning of my test suite function.
All the BeforeEach are run outside if the "bubble", and it creates problems if they start goroutines or create channels. My workaround is to not relly on BeforeEach(func() {...}) and instead replace it with beforeEach = func() {...} and call the function inside the synctest.Test callback.
I did not check Ginkgo code in details, but I guess it would require another kind of It (or Describe) that starts the bubble before calling the BeforeEach...
I am raising this issue to poll for interest, I can also help on the coding part if needed. For now, my workarounds work for me, it makes just test cases a bit more convoluted when using synctest.
Thanks a lot for the feedback :)
Reacted by justin0u0, Nick Fedor, Ivan Drenjanin, Steffen Uhlig and Jonathan Chappelow
Reacted by t, Luca Filipponi, astrid-virta, Ivan Drenjanin and Jonathan Chappelow
looping in @nunnatsa who was asking for this as well.
i'm going to take a look. they've deprecated synctest.Run which would have been easier to manage but I'm going to try and see what I can do. Unfortunately synctest.Test accepts *testing.T instead of an interface so swapping something in might be tricky.
Ideally, though, a spec or container can be decorated with something like InSynctestBubble and all the code spawned in all the nodes associated with the test would run within the context of a shared bubble. That might prove intractable but I'll dig into whether or not it's possible.
hey all - i'm sorry; i just haven't had a lot of time to look at this. There's some degree of complexity here and I'm not sure there's a clean way forward. The Go internal-onlyinternal/synctest package provides some lower-level primitives that could conceivably be integrated into ginkgo. But the public synctest interface is tiny - just Test(t *testing.T, f func(*testing.T)) and Wait().
The former takes a *testing.T instead of an interface - but Ginkgo operates under a single *testing.T and passing it in won't work (synctest.Test will call t.FailNow() which will fail the whole suite instead of just a single test). I could lobby for an update to synctest that takes an interface instead but there will still be issues around Ginkgo's semantics for managing timeouts and instrumenting specs (a whole bunch of calls to the time package).
I think the only really viable approach would be access to Go's internal synctest package which would let Ginkgo create a Bubble per spec and attach just node bodies to the bubble as they run while keeping all the timing/context logic outside of the bubble. I doubt the go maintainers will want to open up that kind of surface area, though.
If anyone sees any other potential approaches please let me know!
Activity
onsi commentedon Oct 3, 2025
looping in @nunnatsa who was asking for this as well.
i'm going to take a look. they've deprecated
synctest.Runwhich would have been easier to manage but I'm going to try and see what I can do. Unfortunatelysynctest.Testaccepts*testing.Tinstead of an interface so swapping something in might be tricky.onsi commentedon Oct 3, 2025
Ideally, though, a spec or container can be decorated with something like
InSynctestBubbleand all the code spawned in all the nodes associated with the test would run within the context of a shared bubble. That might prove intractable but I'll dig into whether or not it's possible.fapo85 commentedon Apr 13, 2026
Is there anything new? I think this would be great for testing timers, too.
onsi commentedon May 9, 2026
hey all - i'm sorry; i just haven't had a lot of time to look at this. There's some degree of complexity here and I'm not sure there's a clean way forward. The Go internal-only
internal/synctestpackage provides some lower-level primitives that could conceivably be integrated into ginkgo. But the publicsynctestinterface is tiny - justTest(t *testing.T, f func(*testing.T))andWait().The former takes a
*testing.Tinstead of an interface - but Ginkgo operates under a single*testing.Tand passing it in won't work (synctest.Testwill callt.FailNow()which will fail the whole suite instead of just a single test). I could lobby for an update tosynctestthat takes an interface instead but there will still be issues around Ginkgo's semantics for managing timeouts and instrumenting specs (a whole bunch of calls to thetimepackage).I think the only really viable approach would be access to Go's internal synctest package which would let Ginkgo create a
Bubbleper spec and attach just node bodies to the bubble as they run while keeping all the timing/context logic outside of the bubble. I doubt the go maintainers will want to open up that kind of surface area, though.If anyone sees any other potential approaches please let me know!
onsi commentedon May 9, 2026
I've opened an issue on
goto see if there's any appetite for improving things:golang/go#79294