Skip to content

Commit 7131884

Browse files
committed
[wip] investigate acceptance test failures
Signed-off-by: Simon Pasquier <[email protected]>
1 parent ecb66f7 commit 7131884

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

test/with_api_v2/acceptance.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
8383
opts: opts,
8484
actions: map[float64][]func(){},
8585
}
86-
// TODO: Should this really be set during creation time? Why not do this
87-
// during Run() time, maybe there is something else long happening between
88-
// creation and running.
89-
opts.baseTime = time.Now()
90-
9186
return test
9287
}
9388

@@ -185,6 +180,10 @@ func (t *AcceptanceTest) Run() {
185180
t.T.Fatal(err)
186181
}
187182

183+
// Set the reference time right before running the test actions to avoid
184+
// test failures due to slow setup of the test environment.
185+
t.opts.baseTime = time.Now()
186+
188187
go t.runActions()
189188

190189
var latest float64
@@ -420,26 +419,26 @@ func (amc *AlertmanagerCluster) Push(at float64, alerts ...*TestAlert) {
420419
// Push declares alerts that are to be pushed to the Alertmanager
421420
// server at a relative point in time.
422421
func (am *Alertmanager) Push(at float64, alerts ...*TestAlert) {
423-
var cas models.PostableAlerts
424-
for i := range alerts {
425-
a := alerts[i].nativeAlert(am.opts)
426-
alert := &models.PostableAlert{
427-
Alert: models.Alert{
428-
Labels: a.Labels,
429-
GeneratorURL: a.GeneratorURL,
430-
},
431-
Annotations: a.Annotations,
432-
}
433-
if a.StartsAt != nil {
434-
alert.StartsAt = *a.StartsAt
435-
}
436-
if a.EndsAt != nil {
437-
alert.EndsAt = *a.EndsAt
422+
am.t.Do(at, func() {
423+
var cas models.PostableAlerts
424+
for i := range alerts {
425+
a := alerts[i].nativeAlert(am.opts)
426+
alert := &models.PostableAlert{
427+
Alert: models.Alert{
428+
Labels: a.Labels,
429+
GeneratorURL: a.GeneratorURL,
430+
},
431+
Annotations: a.Annotations,
432+
}
433+
if a.StartsAt != nil {
434+
alert.StartsAt = *a.StartsAt
435+
}
436+
if a.EndsAt != nil {
437+
alert.EndsAt = *a.EndsAt
438+
}
439+
cas = append(cas, alert)
438440
}
439-
cas = append(cas, alert)
440-
}
441441

442-
am.t.Do(at, func() {
443442
params := alert.PostAlertsParams{}
444443
params.WithContext(context.Background()).WithAlerts(cas)
445444

0 commit comments

Comments
 (0)