Skip to content

Commit

Permalink
整理sync章节
Browse files Browse the repository at this point in the history
  • Loading branch information
william's mac committed Nov 25, 2019
1 parent 64f8430 commit 67fe9d2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sync/v2/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ func TestCounter(t *testing.T) {
})

t.Run("it runs safely concurrently", func(t *testing.T) {
wantedCount := 1000
expectedCount := 1000
counter := NewCounter()

var wg sync.WaitGroup
wg.Add(wantedCount)
wg.Add(expectedCount)

for i := 0; i < wantedCount; i++ {
for i := 0; i < expectedCount; i++ {
go func(w *sync.WaitGroup) {
counter.Inc()
w.Done()
}(&wg)
}
wg.Wait()

assertCounter(t, counter, wantedCount)
assertCounter(t, counter, expectedCount)
})

}

func assertCounter(t *testing.T, got *Counter, want int) {
func assertCounter(t *testing.T, got *Counter, expect int) {
t.Helper()
if got.Value() != want {
t.Errorf("got %d, want %d", got.Value(), want)
if got.Value() != expect {
t.Errorf("got %d, want %d", got.Value(), expect)
}
}

0 comments on commit 67fe9d2

Please sign in to comment.