@@ -24,6 +24,7 @@ import (
24
24
"encoding/json"
25
25
"fmt"
26
26
"io"
27
+ "math/rand"
27
28
"net"
28
29
"net/http"
29
30
"net/http/httptest"
@@ -1206,7 +1207,9 @@ func TestSetLabelsConcurrentWithGetLabel(t *testing.T) {
1206
1207
ts .startServer (t )
1207
1208
defer ts .stopServer (t )
1208
1209
1209
- testUpdateLabels := func (labels , expected map [string ]string ) {
1210
+ testUpdateLabels := func () {
1211
+ labels := map [string ]string {}
1212
+ labels ["zone" ] = fmt .Sprintf ("z-%v" , rand .Intn (100000 ))
1210
1213
buffer := bytes .NewBuffer ([]byte {})
1211
1214
require .Nil (t , json .NewEncoder (buffer ).Encode (labels ))
1212
1215
resp , err := ts .postStatus ("/labels" , "application/json" , buffer )
@@ -1217,29 +1220,23 @@ func TestSetLabelsConcurrentWithGetLabel(t *testing.T) {
1217
1220
}()
1218
1221
require .Equal (t , http .StatusOK , resp .StatusCode )
1219
1222
newLabels := config .GetGlobalConfig ().Labels
1220
- require .Equal (t , newLabels , expected )
1221
- }
1222
-
1223
- labels := map [string ]string {
1224
- "zone" : "us-west-1" ,
1225
- "test" : "123" ,
1226
- }
1227
-
1228
- testUpdateLabels (labels , labels )
1229
-
1230
- updated := map [string ]string {
1231
- "zone" : "bj-1" ,
1223
+ require .Equal (t , newLabels , labels )
1232
1224
}
1233
- labels ["zone" ] = "bj-1"
1234
-
1225
+ done := make (chan struct {})
1235
1226
go func () {
1236
- for i := 0 ; i < 100 ; i ++ {
1237
- config .GetGlobalConfig ().GetTiKVConfig ()
1227
+ for {
1228
+ select {
1229
+ case <- done :
1230
+ return
1231
+ default :
1232
+ config .GetGlobalConfig ().GetTiKVConfig ()
1233
+ }
1238
1234
}
1239
1235
}()
1240
1236
for i := 0 ; i < 100 ; i ++ {
1241
- testUpdateLabels (updated , labels )
1237
+ testUpdateLabels ()
1242
1238
}
1239
+ close (done )
1243
1240
1244
1241
// reset the global variable
1245
1242
config .GetGlobalConfig ().Labels = map [string ]string {}
0 commit comments