Skip to content

Commit f5b80e3

Browse files
committed
Retry availability in case of resilientsingle server
1 parent 264a368 commit f5b80e3

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

test/docker_resilientsingle_default_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestDockerResilientSingleDefault(t *testing.T) {
122122
defer dockerRun3.Close()
123123
defer removeDockerContainer(t, cID3)
124124

125-
if ok := WaitUntilStarterReady(t, whatResilientSingle, dockerRun1, dockerRun2, docker3); ok {
125+
if ok := WaitUntilStarterReady(t, whatResilientSingle, dockerRun1, dockerRun2, dockerRun3); ok {
126126
t.Logf("ResilientSingle start took %s", time.Since(start))
127127
testResilientSingle(t, insecureStarterEndpoint(0), false, false)
128128
testResilientSingle(t, insecureStarterEndpoint(5), false, false)

test/server_util.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,27 @@ func secureStarterEndpoint(portOffset int) string {
7575
// testCluster runs a series of tests to verify a good cluster.
7676
func testCluster(t *testing.T, starterEndpoint string, isSecure bool) client.API {
7777
c := NewStarterClient(t, starterEndpoint)
78-
testProcesses(t, c, "cluster", starterEndpoint, isSecure, false)
78+
testProcesses(t, c, "cluster", starterEndpoint, isSecure, false, 0)
7979
return c
8080
}
8181

8282
// testSingle runs a series of tests to verify a good single server.
8383
func testSingle(t *testing.T, starterEndpoint string, isSecure bool) client.API {
8484
c := NewStarterClient(t, starterEndpoint)
85-
testProcesses(t, c, "single", starterEndpoint, isSecure, false)
85+
testProcesses(t, c, "single", starterEndpoint, isSecure, false, 0)
8686
return c
8787
}
8888

8989
// testResilientSingle runs a series of tests to verify good resilientsingle servers.
9090
func testResilientSingle(t *testing.T, starterEndpoint string, isSecure bool, expectAgencyOnly bool) client.API {
9191
c := NewStarterClient(t, starterEndpoint)
92-
testProcesses(t, c, "resilientsingle", starterEndpoint, isSecure, expectAgencyOnly)
92+
testProcesses(t, c, "resilientsingle", starterEndpoint, isSecure, expectAgencyOnly, time.Second*30)
9393
return c
9494
}
9595

9696
// testProcesses runs a series of tests to verify a good series of database servers.
97-
func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isSecure bool, expectAgencyOnly bool) {
97+
func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isSecure bool,
98+
expectAgencyOnly bool, reachableTimeout time.Duration) {
9899
ctx := context.Background()
99100

100101
// Fetch version
@@ -123,7 +124,7 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
123124
if isVerbose {
124125
t.Logf("Found agent at %s:%d", sp.IP, sp.Port)
125126
}
126-
testArangodReachable(t, sp)
127+
testArangodReachable(t, sp, reachableTimeout)
127128
}
128129
}
129130

@@ -138,7 +139,7 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
138139
if isVerbose {
139140
t.Logf("Found coordinator at %s:%d", sp.IP, sp.Port)
140141
}
141-
testArangodReachable(t, sp)
142+
testArangodReachable(t, sp, reachableTimeout)
142143
}
143144
} else if mode == "cluster" {
144145
t.Errorf("No coordinator found in %s", starterEndpoint)
@@ -155,7 +156,7 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
155156
if isVerbose {
156157
t.Logf("Found dbserver at %s:%d", sp.IP, sp.Port)
157158
}
158-
testArangodReachable(t, sp)
159+
testArangodReachable(t, sp, reachableTimeout)
159160
}
160161
} else if mode == "cluster" {
161162
t.Errorf("No dbserver found in %s", starterEndpoint)
@@ -172,7 +173,7 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
172173
if isVerbose {
173174
t.Logf("Found single at %s:%d", sp.IP, sp.Port)
174175
}
175-
testArangodReachable(t, sp)
176+
testArangodReachable(t, sp, reachableTimeout)
176177
}
177178
} else if (mode == "single" || mode == "resilientsingle") && !expectAgencyOnly {
178179
t.Errorf("No single found in %s", starterEndpoint)
@@ -181,14 +182,22 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
181182

182183
// testArangodReachable tries to call some HTTP API methods of the given server process to make sure
183184
// it is reachable.
184-
func testArangodReachable(t *testing.T, sp client.ServerProcess) {
185+
func testArangodReachable(t *testing.T, sp client.ServerProcess, timeout time.Duration) {
185186
scheme := "http"
186187
if sp.IsSecure {
187188
scheme = "https"
188189
}
189-
url := fmt.Sprintf("%s://%s:%d/_api/version", scheme, sp.IP, sp.Port)
190-
_, err := httpClient.Get(url)
191-
if err != nil {
192-
t.Errorf("Failed to reach arangod at %s:%d (%#v)", sp.IP, sp.Port, err)
190+
start := time.Now()
191+
for {
192+
url := fmt.Sprintf("%s://%s:%d/_api/version", scheme, sp.IP, sp.Port)
193+
_, err := httpClient.Get(url)
194+
if err == nil {
195+
return
196+
}
197+
if timeout == 0 || time.Since(start) > timeout {
198+
t.Errorf("Failed to reach arangod at %s:%d (%#v)", sp.IP, sp.Port, err)
199+
return
200+
}
201+
time.Sleep(time.Second)
193202
}
194203
}

0 commit comments

Comments
 (0)