Skip to content

Commit

Permalink
go.net/ipv6: fix overlooked execution reorder in test
Browse files Browse the repository at this point in the history
The test expects to run opt.clear just after opt.set.

Fixes golang/go#5696.

R=dave, fullung
CC=golang-dev
https://golang.org/cl/10285044
  • Loading branch information
cixtor committed Jun 29, 2013
1 parent 080e651 commit d470d77
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ipv6/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,26 @@ func TestControlFlags(t *testing.T) {
tf := FlagInterface | FlagPathMTU
opt := rawOpt{cflags: tf | FlagHopLimit}

type ffn func(ControlFlags)
// This loop runs methods of raw.Opt concurrently for testing
// concurrent access to the rawOpt. The first entry shold be
// opt.set and the last entry should be opt.clear.
tfns := []func(ControlFlags){opt.set, opt.clear, opt.clear}
ch := make(chan bool)
var wg sync.WaitGroup
for _, fn := range []ffn{opt.set, opt.clear, opt.clear} {
for i, fn := range tfns {
wg.Add(1)
go func(fn ffn) {
go func(i int, fn func(ControlFlags)) {
defer wg.Done()
switch i {
case 0:
close(ch)
case len(tfns) - 1:
<-ch
}
opt.Lock()
defer opt.Unlock()
fn(tf)
}(fn)
}(i, fn)
}
wg.Wait()

Expand Down

0 comments on commit d470d77

Please sign in to comment.