package ex import "sync" import "testing" type Item struct{} func TestAppend(t *testing.T) { var list []Item n := 2 wg := sync.WaitGroup{} wg.Add(n) for i := 0; i < n; i++ { go func() { defer wg.Done() list = append(list, Item{}) }() } wg.Wait() }