|
@@ -13,16 +13,26 @@ func TestControlFlags(t *testing.T) {
|
|
|
tf := FlagInterface | FlagPathMTU
|
|
tf := FlagInterface | FlagPathMTU
|
|
|
opt := rawOpt{cflags: tf | FlagHopLimit}
|
|
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
|
|
var wg sync.WaitGroup
|
|
|
- for _, fn := range []ffn{opt.set, opt.clear, opt.clear} {
|
|
|
|
|
|
|
+ for i, fn := range tfns {
|
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
|
- go func(fn ffn) {
|
|
|
|
|
|
|
+ go func(i int, fn func(ControlFlags)) {
|
|
|
defer wg.Done()
|
|
defer wg.Done()
|
|
|
|
|
+ switch i {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ close(ch)
|
|
|
|
|
+ case len(tfns) - 1:
|
|
|
|
|
+ <-ch
|
|
|
|
|
+ }
|
|
|
opt.Lock()
|
|
opt.Lock()
|
|
|
defer opt.Unlock()
|
|
defer opt.Unlock()
|
|
|
fn(tf)
|
|
fn(tf)
|
|
|
- }(fn)
|
|
|
|
|
|
|
+ }(i, fn)
|
|
|
}
|
|
}
|
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
|