|
@@ -802,6 +802,46 @@ func TestHTTPClusterClientAutoSyncFail(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// TestHTTPClusterClientSyncPinEndpoint tests that Sync() pins the endpoint when
|
|
|
|
|
+// it gets the exactly same member list as before.
|
|
|
|
|
+func TestHTTPClusterClientSyncPinEndpoint(t *testing.T) {
|
|
|
|
|
+ cf := newStaticHTTPClientFactory([]staticHTTPResponse{
|
|
|
|
|
+ staticHTTPResponse{
|
|
|
|
|
+ resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}},
|
|
|
|
|
+ body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`),
|
|
|
|
|
+ },
|
|
|
|
|
+ staticHTTPResponse{
|
|
|
|
|
+ resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}},
|
|
|
|
|
+ body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`),
|
|
|
|
|
+ },
|
|
|
|
|
+ staticHTTPResponse{
|
|
|
|
|
+ resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}},
|
|
|
|
|
+ body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`),
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ hc := &httpClusterClient{
|
|
|
|
|
+ clientFactory: cf,
|
|
|
|
|
+ rand: rand.New(rand.NewSource(0)),
|
|
|
|
|
+ }
|
|
|
|
|
+ err := hc.reset([]string{"http://127.0.0.1:4003", "http://127.0.0.1:2379", "http://127.0.0.1:4001", "http://127.0.0.1:4002"})
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatalf("unexpected error during setup: %#v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ pinnedEndpoint := hc.endpoints[hc.pinned]
|
|
|
|
|
+
|
|
|
|
|
+ for i := 0; i < 3; i++ {
|
|
|
|
|
+ err = hc.Sync(context.Background())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatalf("#%d: unexpected error during Sync: %#v", i, err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if g := hc.endpoints[hc.pinned]; g != pinnedEndpoint {
|
|
|
|
|
+ t.Errorf("#%d: pinned endpoint = %s, want %s", i, g, pinnedEndpoint)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestHTTPClusterClientResetFail(t *testing.T) {
|
|
func TestHTTPClusterClientResetFail(t *testing.T) {
|
|
|
tests := [][]string{
|
|
tests := [][]string{
|
|
|
// need at least one endpoint
|
|
// need at least one endpoint
|