---
title: "Discussion on \"Go synctest：徹底解決並發測試的痛點\" | Hashnode"
description: "Discussion on \"Go synctest：徹底解決並發測試的痛點\". Go introduces synctest for precise goroutine synchronization, enhancing concurrent testing accuracy"
url: "https://hashnode.com/posts/go-synctest/687bc2dfac7de9dd7b16e818"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Go synctest：徹底解決並發測試的痛點](https://ganhua.wang/go-synctest?utm_source=hashnode&utm_medium=feed)

Go introduces synctest for precise goroutine synchronization, enhancing concurrent testing accuracy

Jul 19, 2025 · 10 min read · ganhua.wang  
Read the article

-   [#go](https://hashnode.com/tag/go)

## Written by

[雷N](https://hashnode.com/@nathanrayn)

@nathanrayn · Taipei, Taiwan

  
[View profile](https://hashnode.com/@nathanrayn)

## Responses 1

Markdown supported · ⌘↵ to post

[Ricky](https://hashnode.com/@rickylin)

[Nov 7, 2025](https://hashnode.com/posts/go-synctest/687bc2dfac7de9dd7b16e818/comment/690d91b04ebd4e3a75bad13d)

1.25 的 synctest 看起來沒有 Run

應該是這樣吧

```
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() // 等到所有 goroutine 都卡住
        if called {
            t.Fatal("AfterFunc 在 cancel 前就被呼叫")
        }

        cancel()

        synctest.Wait() // 再等一次
        if !called {
            t.Fatal("AfterFunc 沒有在 cancel 後被呼叫")
        }
    })
}
```
