This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 21 · May 19 – 25, 2025

testing/synctest: new package for testing concurrent code

Worth knowingtooling

What changed
A new package testing/synctest was added, providing Test and Wait helpers for concurrent testing.
Production impact
The source does not say.
Try it
Import testing/synctest and call synctest.Test(t, func(t *testing.T) { … }).
Source
github.com/golang/go/issues/67434

Understand it, then run it

A new package called testing/synctest was added to the Go standard library. It lets you run a test in its own “bubble” of goroutines and then wait until all of those goroutines are idle or finished. The main functions are Test and Wait. Test runs a function in a new bubble and blocks until every goroutine in that bubble exits. Wait can be called inside that bubble to pause until every other goroutine in the bubble is blocked on something like a channel or a timer. This makes it easier to test code that uses timers or runs many goroutines without having to sleep for real time or guess when work is done.

After the change ships

go · the proposal's code; it does not compile until the change ships

// This code does not compile until the synctest package is available in Go 1.27.1.
package main

import (
	"testing"

	"golang.org/x/testing/synctest"
)

func main() {
	synctest.Test(&testing.T{}, func(t *testing.T) {
		// test body
	})
}

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed