Commit d470d778 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: fix overlooked execution reorder in test

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
parent 080e6515
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment