浏览代码

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
Mikio Hara 12 年之前
父节点
当前提交
d470d77814
共有 1 个文件被更改,包括 14 次插入4 次删除
  1. 14 4
      ipv6/control_test.go

+ 14 - 4
ipv6/control_test.go

@@ -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()