Skip to content

Commit 599aa39

Browse files
committed
Update testutil HTTPGet refresh strategy
1. extend the refresh interval from 0.1 second to 1 second 2. normalize all calls to HTTPGet to repeat 5 times (instead of the mix of 10, 30, 5 etc) We can in the future assess case by case if some tests need more time. Note that the replacement does not reduce any existing test timeout (30 * 0.1 < 5) Signed-off-by: apostasie <[email protected]>
1 parent 875ae4c commit 599aa39

15 files changed

+21
-21
lines changed

cmd/nerdctl/compose/compose_run_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ services:
142142
}()
143143

144144
checkNginx := func() error {
145-
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 10, false)
145+
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 5, false)
146146
if err != nil {
147147
return err
148148
}
@@ -201,7 +201,7 @@ services:
201201
}()
202202

203203
checkNginx := func() error {
204-
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 10, false)
204+
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 5, false)
205205
if err != nil {
206206
return err
207207
}

cmd/nerdctl/compose/compose_up_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ COPY index.html /usr/share/nginx/html/index.html
100100
base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d", "--build").AssertOK()
101101
defer base.ComposeCmd("-f", comp.YAMLFullPath(), "down", "-v").Run()
102102

103-
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 50, false)
103+
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 5, false)
104104
assert.NilError(t, err)
105105
respBody, err := io.ReadAll(resp.Body)
106106
assert.NilError(t, err)

cmd/nerdctl/container/container_run_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func TestPortBindingWithCustomHost(t *testing.T) {
653653
Errors: []error{},
654654
Output: expect.All(
655655
func(stdout string, t tig.T) {
656-
resp, err := nettestutil.HTTPGet(address, 30, false)
656+
resp, err := nettestutil.HTTPGet(address, 5, false)
657657
assert.NilError(t, err)
658658

659659
respBody, err := io.ReadAll(resp.Body)

cmd/nerdctl/container/container_run_network_base_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func baseTestRunPort(t *testing.T, nginxImage string, nginxIndexHTMLSnippet stri
155155
hostPort: "7000-7005",
156156
containerPort: "80-85",
157157
connectURLPort: 7001,
158-
err: "error after 30 attempts",
158+
err: "error after 5 attempts",
159159
runShouldSuccess: true,
160160
},
161161
{
@@ -209,7 +209,7 @@ func baseTestRunPort(t *testing.T, nginxImage string, nginxIndexHTMLSnippet stri
209209
return
210210
}
211211

212-
resp, err := nettestutil.HTTPGet(connectURL, 30, false)
212+
resp, err := nettestutil.HTTPGet(connectURL, 5, false)
213213
if tc.err != "" {
214214
assert.ErrorContains(t, err, tc.err)
215215
return

cmd/nerdctl/container/container_run_network_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestRunPortWithNoHostPort(t *testing.T) {
248248
return
249249
}
250250
connectURL := fmt.Sprintf("http://%s:%s", "127.0.0.1", paramsMap["portNumber"])
251-
resp, err := nettestutil.HTTPGet(connectURL, 30, false)
251+
resp, err := nettestutil.HTTPGet(connectURL, 5, false)
252252
assert.NilError(t, err)
253253
respBody, err := io.ReadAll(resp.Body)
254254
assert.NilError(t, err)
@@ -333,15 +333,15 @@ func TestUniqueHostPortAssignement(t *testing.T) {
333333

334334
// Make HTTP GET request to container 1
335335
connectURL1 := fmt.Sprintf("http://%s:%s", "127.0.0.1", port1)
336-
resp1, err := nettestutil.HTTPGet(connectURL1, 30, false)
336+
resp1, err := nettestutil.HTTPGet(connectURL1, 5, false)
337337
assert.NilError(t, err)
338338
respBody1, err := io.ReadAll(resp1.Body)
339339
assert.NilError(t, err)
340340
assert.Assert(t, strings.Contains(string(respBody1), testutil.NginxAlpineIndexHTMLSnippet))
341341

342342
// Make HTTP GET request to container 2
343343
connectURL2 := fmt.Sprintf("http://%s:%s", "127.0.0.1", port2)
344-
resp2, err := nettestutil.HTTPGet(connectURL2, 30, false)
344+
resp2, err := nettestutil.HTTPGet(connectURL2, 5, false)
345345
assert.NilError(t, err)
346346
respBody2, err := io.ReadAll(resp2.Body)
347347
assert.NilError(t, err)

cmd/nerdctl/container/container_run_restart_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestRunRestart(t *testing.T) {
6969
}
7070
return nil
7171
}
72-
assert.NilError(t, check(30))
72+
assert.NilError(t, check(5))
7373

7474
base.KillDaemon()
7575
base.EnsureDaemonActive()

cmd/nerdctl/container/container_stop_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ func TestStopStart(t *testing.T) {
6666
return nil
6767
}
6868

69-
assert.NilError(t, check(30))
69+
assert.NilError(t, check(5))
7070
base.Cmd("stop", testContainerName).AssertOK()
7171
base.Cmd("exec", testContainerName, "ps").AssertFail()
7272
if check(1) == nil {
7373
t.Fatal("expected to get an error")
7474
}
7575
base.Cmd("start", testContainerName).AssertOK()
76-
assert.NilError(t, check(30))
76+
assert.NilError(t, check(5))
7777
}
7878

7979
func TestStopWithStopSignal(t *testing.T) {

cmd/nerdctl/container/multi_platform_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ RUN uname -m > /usr/share/nginx/html/index.html
163163
}
164164

165165
for testURL, expectedIndexHTML := range testCases {
166-
resp, err := nettestutil.HTTPGet(testURL, 50, false)
166+
resp, err := nettestutil.HTTPGet(testURL, 5, false)
167167
assert.NilError(t, err)
168168
respBody, err := io.ReadAll(resp.Body)
169169
assert.NilError(t, err)

cmd/nerdctl/helpers/testing_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func ComposeUp(t *testing.T, base *testutil.Base, dockerComposeYAML string, opts
7474
base.Cmd("network", "inspect", fmt.Sprintf("%s_default", projectName)).AssertOK()
7575

7676
checkWordpress := func() error {
77-
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 10, false)
77+
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8080", 5, false)
7878
if err != nil {
7979
return err
8080
}

cmd/nerdctl/ipfs/ipfs_compose_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ COPY index.html /usr/share/nginx/html/index.html
256256
testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
257257
return &test.Expected{
258258
Output: func(stdout string, t tig.T) {
259-
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8081", 10, false)
259+
resp, err := nettestutil.HTTPGet("http://127.0.0.1:8081", 5, false)
260260
assert.NilError(t, err)
261261
respBody, err := io.ReadAll(resp.Body)
262262
assert.NilError(t, err)

0 commit comments

Comments
 (0)