test(apiserver): deflake TestClientReceivedGOAWAY

protect `localAddr` from concurrent read and write

Signed-off-by: knight42 <anonymousknight96@gmail.com>
This commit is contained in:
knight42 2020-09-04 23:35:53 +08:00 committed by Jordan Liggitt
parent 6125e6b65a
commit 1f235c858c

View File

@ -342,6 +342,7 @@ func TestClientReceivedGOAWAY(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var mu sync.Mutex
// localAddr indicates how many TCP connection set up
localAddr := make([]string, 0)
@ -350,7 +351,10 @@ func TestClientReceivedGOAWAY(t *testing.T) {
if err != nil {
t.Fatalf("unexpect connection err: %v", err)
}
mu.Lock()
localAddr = append(localAddr, conn.LocalAddr().String())
mu.Unlock()
return
})
if err != nil {