Skip to content

Commit 2a6cb72

Browse files
authored
Speed up VA test. (letsencrypt#5261)
We had a test that relied on sleeping to hit a timeout. This doesn't remove the sleep, but it does tighten the duration significantly. Brings unit test time for the VA from 11 seconds to 1.7 seconds on my machine.
1 parent aa20bca commit 2a6cb72

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

va/va_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ func (s *multiSrv) setAllowedUAs(allowedUAs map[string]bool) {
174174
s.allowedUAs = allowedUAs
175175
}
176176

177+
const slowRemoteSleepMillis = 1000
178+
177179
func httpMultiSrv(t *testing.T, token string, allowedUAs map[string]bool) *multiSrv {
178180
m := http.NewServeMux()
179181

@@ -182,7 +184,7 @@ func httpMultiSrv(t *testing.T, token string, allowedUAs map[string]bool) *multi
182184

183185
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
184186
if r.UserAgent() == "slow remote" {
185-
time.Sleep(time.Second * 5)
187+
time.Sleep(slowRemoteSleepMillis)
186188
}
187189
ms.mu.Lock()
188190
defer ms.mu.Unlock()
@@ -608,16 +610,17 @@ func TestMultiVAEarlyReturn(t *testing.T) {
608610
t.Error("expected prob from PerformValidation, got nil")
609611
}
610612

611-
elapsed := time.Since(start).Round(time.Millisecond).Seconds()
613+
elapsed := time.Since(start).Round(time.Millisecond).Milliseconds()
612614

613-
// The slow UA should sleep for 5 seconds. In the early return case the
614-
// first remote VA should fail the overall validation and a prob should be
615-
// returned quickly. In the non-early return case we don't expect
616-
// a problem for 5s.
617-
if tc.EarlyReturn && elapsed > 4.0 {
615+
// The slow UA should sleep for `slowRemoteSleepMillis`. In the early return
616+
// case the first remote VA should fail the overall validation and a prob
617+
// should be returned quickly (i.e. in less than half of `slowRemoteSleepMillis`).
618+
// In the non-early return case we don't expect a problem until
619+
// `slowRemoteSleepMillis`.
620+
if tc.EarlyReturn && elapsed > slowRemoteSleepMillis/2 {
618621
t.Errorf(
619-
"Expected an early return from PerformValidation in < 4.0s, took %f",
620-
elapsed)
622+
"Expected an early return from PerformValidation in < %d ms, took %d ms",
623+
slowRemoteSleepMillis/2, elapsed)
621624
}
622625
})
623626
}

0 commit comments

Comments
 (0)