ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

Synctest support

Open wuzuf opened this issue 2 months ago • 2 comments

Dear team,

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 :)

wuzuf avatar Oct 03 '25 08:10 wuzuf

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.

onsi avatar Oct 03 '25 23:10 onsi

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.

onsi avatar Oct 03 '25 23:10 onsi