go-synctest
func TestAfterFunc(t *testing.T) {
synctest.Test(t, func(*testing.T) {
ctx, cancel := context.WithCancel(context.Background())
called := false
context.AfterFunc(ctx, func() { called = true })
synctest.Wait() // Wait until all goroutines are blocked
if called {
t.Fatal("AfterFunc was called before cancel")
}
cancel()
synctest.Wait() // Wait again
if !called {
t.Fatal("AfterFunc was not called after cancel")
}
})
}
