Skip to content

Synctest support #1601

Open
Open

Description

@wuzuf

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

Activity

  1. onsi commented on Oct 3, 2025

    @onsi
    Owner

    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.

  2. onsi commented on Oct 3, 2025

    @onsi
    Owner

    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.

  3. fapo85 commented on Apr 13, 2026

    @fapo85

    Is there anything new? I think this would be great for testing timers, too.

  4. onsi commented on May 9, 2026

    @onsi
    Owner

    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!

  5. onsi commented on May 9, 2026

    @onsi
    Owner

    I've opened an issue on go to see if there's any appetite for improving things:

    golang/go#79294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions