@@ -83,11 +83,6 @@ func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
83
83
opts : opts ,
84
84
actions : map [float64 ][]func (){},
85
85
}
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
-
91
86
return test
92
87
}
93
88
@@ -185,6 +180,10 @@ func (t *AcceptanceTest) Run() {
185
180
t .T .Fatal (err )
186
181
}
187
182
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
+
188
187
go t .runActions ()
189
188
190
189
var latest float64
@@ -420,26 +419,26 @@ func (amc *AlertmanagerCluster) Push(at float64, alerts ...*TestAlert) {
420
419
// Push declares alerts that are to be pushed to the Alertmanager
421
420
// server at a relative point in time.
422
421
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 )
438
440
}
439
- cas = append (cas , alert )
440
- }
441
441
442
- am .t .Do (at , func () {
443
442
params := alert.PostAlertsParams {}
444
443
params .WithContext (context .Background ()).WithAlerts (cas )
445
444
0 commit comments