@@ -83,7 +83,7 @@ func TestPostToApmServerDataCompressed(t *testing.T) {
83
83
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
84
84
)
85
85
require .NoError (t , err )
86
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
86
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
87
87
}
88
88
89
89
func TestPostToApmServerDataNotCompressed (t * testing.T ) {
@@ -129,7 +129,7 @@ func TestPostToApmServerDataNotCompressed(t *testing.T) {
129
129
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
130
130
)
131
131
require .NoError (t , err )
132
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
132
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
133
133
}
134
134
135
135
func TestGracePeriod (t * testing.T ) {
@@ -178,7 +178,7 @@ func TestSetHealthyTransport(t *testing.T) {
178
178
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
179
179
)
180
180
require .NoError (t , err )
181
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
181
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
182
182
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
183
183
assert .Equal (t , apmClient .ReconnectionCount , - 1 )
184
184
}
@@ -192,7 +192,7 @@ func TestSetFailingTransport(t *testing.T) {
192
192
)
193
193
require .NoError (t , err )
194
194
apmClient .ReconnectionCount = 0
195
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
195
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
196
196
assert .Equal (t , apmproxy .Failing , apmClient .Status )
197
197
assert .Equal (t , 1 , apmClient .ReconnectionCount )
198
198
}
@@ -203,8 +203,8 @@ func TestSetPendingTransport(t *testing.T) {
203
203
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
204
204
)
205
205
require .NoError (t , err )
206
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
207
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
206
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
207
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
208
208
require .Eventually (t , func () bool {
209
209
return ! apmClient .IsUnhealthy ()
210
210
}, 7 * time .Second , 50 * time .Millisecond )
@@ -218,8 +218,8 @@ func TestSetPendingTransportExplicitly(t *testing.T) {
218
218
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
219
219
)
220
220
require .NoError (t , err )
221
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
222
- apmClient .UpdateStatus (context . Background (), apmproxy .Started )
221
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
222
+ apmClient .UpdateStatus (t . Context (), apmproxy .Started )
223
223
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
224
224
assert .Equal (t , apmClient .ReconnectionCount , - 1 )
225
225
}
@@ -230,8 +230,8 @@ func TestSetInvalidTransport(t *testing.T) {
230
230
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
231
231
)
232
232
require .NoError (t , err )
233
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
234
- apmClient .UpdateStatus (context . Background (), "Invalid" )
233
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
234
+ apmClient .UpdateStatus (t . Context (), "Invalid" )
235
235
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
236
236
assert .Equal (t , apmClient .ReconnectionCount , - 1 )
237
237
}
@@ -274,12 +274,12 @@ func TestEnterBackoffFromHealthy(t *testing.T) {
274
274
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
275
275
)
276
276
require .NoError (t , err )
277
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
277
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
278
278
279
279
// Close the APM server early so that POST requests fail and that backoff is enabled
280
280
apmServer .Close ()
281
281
282
- if err := apmClient .PostToApmServer (context . Background (), agentData ); err != nil {
282
+ if err := apmClient .PostToApmServer (t . Context (), agentData ); err != nil {
283
283
return
284
284
}
285
285
// No way to know for sure if failing or pending (0 sec grace period)
@@ -329,14 +329,14 @@ func TestEnterBackoffFromFailing(t *testing.T) {
329
329
)
330
330
require .NoError (t , err )
331
331
332
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
333
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
332
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
333
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
334
334
require .Eventually (t , func () bool {
335
335
return ! apmClient .IsUnhealthy ()
336
336
}, 7 * time .Second , 50 * time .Millisecond )
337
337
assert .Equal (t , apmproxy .Started , apmClient .Status )
338
338
339
- require .Error (t , apmClient .PostToApmServer (context . Background (), agentData ))
339
+ require .Error (t , apmClient .PostToApmServer (t . Context (), agentData ))
340
340
assert .Equal (t , apmproxy .Failing , apmClient .Status )
341
341
assert .Equal (t , 1 , apmClient .ReconnectionCount )
342
342
}
@@ -383,14 +383,14 @@ func TestAPMServerRecovery(t *testing.T) {
383
383
)
384
384
require .NoError (t , err )
385
385
386
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
387
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
386
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
387
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
388
388
require .Eventually (t , func () bool {
389
389
return ! apmClient .IsUnhealthy ()
390
390
}, 7 * time .Second , 50 * time .Millisecond )
391
391
assert .Equal (t , apmproxy .Started , apmClient .Status )
392
392
393
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
393
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
394
394
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
395
395
}
396
396
@@ -428,13 +428,13 @@ func TestAPMServerAuthFails(t *testing.T) {
428
428
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
429
429
)
430
430
require .NoError (t , err )
431
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
432
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
431
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
432
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
433
433
require .Eventually (t , func () bool {
434
434
return ! apmClient .IsUnhealthy ()
435
435
}, 7 * time .Second , 50 * time .Millisecond )
436
436
assert .Equal (t , apmproxy .Started , apmClient .Status )
437
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
437
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
438
438
assert .NotEqual (t , apmproxy .Healthy , apmClient .Status )
439
439
}
440
440
@@ -482,11 +482,11 @@ func TestAPMServerRatelimit(t *testing.T) {
482
482
assert .Equal (t , apmproxy .Started , apmClient .Status )
483
483
484
484
// First request fails but does not trigger the backoff
485
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
485
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
486
486
assert .Equal (t , apmproxy .RateLimited , apmClient .Status )
487
487
488
488
// Followup request is successful
489
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
489
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
490
490
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
491
491
}
492
492
@@ -534,11 +534,11 @@ func TestAPMServerClientFail(t *testing.T) {
534
534
assert .Equal (t , apmproxy .Started , apmClient .Status )
535
535
536
536
// First request fails but does not trigger the backoff
537
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
537
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
538
538
assert .Equal (t , apmproxy .ClientFailing , apmClient .Status )
539
539
540
540
// Followup request is successful
541
- require .NoError (t , apmClient .PostToApmServer (context . Background (), agentData ))
541
+ require .NoError (t , apmClient .PostToApmServer (t . Context (), agentData ))
542
542
assert .Equal (t , apmproxy .Healthy , apmClient .Status )
543
543
}
544
544
@@ -581,13 +581,13 @@ func TestContinuedAPMServerFailure(t *testing.T) {
581
581
apmproxy .WithLogger (zaptest .NewLogger (t ).Sugar ()),
582
582
)
583
583
require .NoError (t , err )
584
- apmClient .UpdateStatus (context . Background (), apmproxy .Healthy )
585
- apmClient .UpdateStatus (context . Background (), apmproxy .Failing )
584
+ apmClient .UpdateStatus (t . Context (), apmproxy .Healthy )
585
+ apmClient .UpdateStatus (t . Context (), apmproxy .Failing )
586
586
require .Eventually (t , func () bool {
587
587
return ! apmClient .IsUnhealthy ()
588
588
}, 7 * time .Second , 50 * time .Millisecond )
589
589
assert .Equal (t , apmproxy .Started , apmClient .Status )
590
- require .Error (t , apmClient .PostToApmServer (context . Background (), agentData ))
590
+ require .Error (t , apmClient .PostToApmServer (t . Context (), agentData ))
591
591
assert .Equal (t , apmproxy .Failing , apmClient .Status )
592
592
}
593
593
@@ -628,7 +628,7 @@ func TestForwardApmData(t *testing.T) {
628
628
require .NoError (t , err )
629
629
630
630
// Start forwarding APM data
631
- ctx , cancel := context .WithCancel (context . Background ())
631
+ ctx , cancel := context .WithCancel (t . Context ())
632
632
var wg sync.WaitGroup
633
633
wg .Add (1 )
634
634
go func () {
@@ -703,7 +703,7 @@ func BenchmarkFlushAPMData(b *testing.B) {
703
703
for j := 0 ; j < 99 ; j ++ {
704
704
apmClient .LambdaDataChannel <- []byte (`{"log":{"message":this is test log"}}` )
705
705
}
706
- apmClient .FlushAPMData (context . Background ())
706
+ apmClient .FlushAPMData (b . Context ())
707
707
}
708
708
}
709
709
@@ -742,7 +742,7 @@ func BenchmarkPostToAPM(b *testing.B) {
742
742
b .ReportAllocs ()
743
743
b .ResetTimer ()
744
744
for i := 0 ; i < b .N ; i ++ {
745
- if err := apmClient .PostToApmServer (context . Background (), agentData ); err != nil {
745
+ if err := apmClient .PostToApmServer (b . Context (), agentData ); err != nil {
746
746
b .Fatal (err )
747
747
}
748
748
}
0 commit comments