-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints_test.go
71 lines (61 loc) · 1.84 KB
/
endpoints_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package drovedns
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestRaceCondidtion(t *testing.T) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
mux.HandleFunc("/apis/v1/ping", func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
// Send response to be tested
// rw.Write([]byte(`OK`))
rw.WriteHeader(http.StatusOK)
})
mux.HandleFunc("/apis/v1/endpoints", func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
// Send response to be tested
// rw.Write([]byte(`OK`))
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusOK)
fmt.Fprint(rw, `{"status": "ok", "message": "ok", "data":[{"appId": "PS", "vhost": "ps.blah", "tags": {}, "hosts":[{"host": "host", "port": 1234, "portType": "http"}]}]}`)
})
mux.HandleFunc("/apis/v1/cluster/events/summary", func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
// Send response to be tested
// rw.Write([]byte(`OK`))
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusOK)
fmt.Fprint(rw, `{"status": "SUCCESS", "message": "ok", "data":{"eventsCount":{"APP_STATE_CHANGE": 1}, "lastSyncTime": 1}}`)
})
// Close the server when test finishes
defer server.Close()
// Use Client & URL from our local test server
client := NewDroveClient(DroveConfig{Endpoint: server.URL, AuthConfig: DroveAuthConfig{AccessToken: ""}})
client.Init()
underTest := newDroveEndpoints(&client)
go func() {
for i := 0; i < 100; i++ {
go func() {
apps := underTest.getApps()
if apps == nil {
return
}
for i, _ := range apps.Apps {
t.Logf("%+v", apps.Apps[i].Hosts)
}
}()
}
}()
go func() {
for i := 0; i < 100; i++ {
go func() {
underTest.setApps(&DroveAppsResponse{})
}()
}
}()
time.Sleep(1)
}