Skip to content

Commit 4235850

Browse files
committed
update test
Signed-off-by: gengliqi <[email protected]>
1 parent 0edf6ee commit 4235850

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

server/http_handler_test.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/json"
2525
"fmt"
2626
"io"
27+
"math/rand"
2728
"net"
2829
"net/http"
2930
"net/http/httptest"
@@ -1206,7 +1207,9 @@ func TestSetLabelsConcurrentWithGetLabel(t *testing.T) {
12061207
ts.startServer(t)
12071208
defer ts.stopServer(t)
12081209

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))
12101213
buffer := bytes.NewBuffer([]byte{})
12111214
require.Nil(t, json.NewEncoder(buffer).Encode(labels))
12121215
resp, err := ts.postStatus("/labels", "application/json", buffer)
@@ -1217,29 +1220,23 @@ func TestSetLabelsConcurrentWithGetLabel(t *testing.T) {
12171220
}()
12181221
require.Equal(t, http.StatusOK, resp.StatusCode)
12191222
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)
12321224
}
1233-
labels["zone"] = "bj-1"
1234-
1225+
done := make(chan struct{})
12351226
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+
}
12381234
}
12391235
}()
12401236
for i := 0; i < 100; i++ {
1241-
testUpdateLabels(updated, labels)
1237+
testUpdateLabels()
12421238
}
1239+
close(done)
12431240

12441241
// reset the global variable
12451242
config.GetGlobalConfig().Labels = map[string]string{}

0 commit comments

Comments
 (0)