Skip to content

Commit 9c6f7e9

Browse files
authored
test: check condition early for TestHTTPReloadEnableBehavior (#5418)
we're relying on assert.Eventually with a wait time of 3s we call it twice per test in 4 total tests minimum test time should be 3*2*4=24s Update assertion to check the condition before calling eventually Test time went from 24.101s to 0.264s
1 parent cdff378 commit 9c6f7e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/pkg/agent/application/monitoring/server_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func waitOnReturnCode(t *testing.T, expectedReturnCode int, formValue string, re
146146
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
147147
defer cancel()
148148
client := &http.Client{}
149-
require.Eventually(t, func() bool {
149+
fastEventually(t, func() bool {
150150
path := fmt.Sprintf("http://%s/liveness%s", rel.Addr().String(), formValue)
151151
t.Logf("checking %s", path)
152152
req, err := http.NewRequestWithContext(ctx, "GET", path, nil)
@@ -163,6 +163,14 @@ func waitOnReturnCode(t *testing.T, expectedReturnCode int, formValue string, re
163163
}, time.Second*30, time.Second*3)
164164
}
165165

166+
func fastEventually(t *testing.T, condition func() bool, waitFor time.Duration, tick time.Duration) {
167+
if condition() {
168+
return
169+
}
170+
171+
require.Eventually(t, condition, waitFor, tick)
172+
}
173+
166174
func TestIsHTTPUrl(t *testing.T) {
167175

168176
tests := []struct {

0 commit comments

Comments
 (0)