@@ -372,27 +372,30 @@ func TestAgentStats(t *testing.T) {
372
372
373
373
registry := prometheus .NewRegistry ()
374
374
375
+ ctx , cancelFunc := context .WithCancel (context .Background ())
376
+ defer cancelFunc ()
377
+
375
378
// given
376
379
var err error
377
380
var i int64
378
381
for i = 0 ; i < 3 ; i ++ {
379
- _ , err = agent1 .PostStats (context . Background () , & agentsdk.Stats {
382
+ _ , err = agent1 .PostStats (ctx , & agentsdk.Stats {
380
383
TxBytes : 1 + i , RxBytes : 2 + i ,
381
384
SessionCountVSCode : 3 + i , SessionCountJetBrains : 4 + i , SessionCountReconnectingPTY : 5 + i , SessionCountSSH : 6 + i ,
382
385
ConnectionCount : 7 + i , ConnectionMedianLatencyMS : 8000 ,
383
386
ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
384
387
})
385
388
require .NoError (t , err )
386
389
387
- _ , err = agent2 .PostStats (context . Background () , & agentsdk.Stats {
390
+ _ , err = agent2 .PostStats (ctx , & agentsdk.Stats {
388
391
TxBytes : 2 + i , RxBytes : 4 + i ,
389
392
SessionCountVSCode : 6 + i , SessionCountJetBrains : 8 + i , SessionCountReconnectingPTY : 10 + i , SessionCountSSH : 12 + i ,
390
393
ConnectionCount : 8 + i , ConnectionMedianLatencyMS : 10000 ,
391
394
ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
392
395
})
393
396
require .NoError (t , err )
394
397
395
- _ , err = agent3 .PostStats (context . Background () , & agentsdk.Stats {
398
+ _ , err = agent3 .PostStats (ctx , & agentsdk.Stats {
396
399
TxBytes : 3 + i , RxBytes : 6 + i ,
397
400
SessionCountVSCode : 12 + i , SessionCountJetBrains : 14 + i , SessionCountReconnectingPTY : 16 + i , SessionCountSSH : 18 + i ,
398
401
ConnectionCount : 9 + i , ConnectionMedianLatencyMS : 12000 ,
@@ -405,7 +408,7 @@ func TestAgentStats(t *testing.T) {
405
408
//
406
409
// Set initialCreateAfter to some time in the past, so that AgentStats would include all above PostStats,
407
410
// and it doesn't depend on the real time.
408
- cancel , err := prometheusmetrics .AgentStats (context . Background () , slogtest .Make (t , nil ), registry , db , time .Now ().Add (- time .Minute ), time .Millisecond )
411
+ cancel , err := prometheusmetrics .AgentStats (ctx , slogtest .Make (t , nil ), registry , db , time .Now ().Add (- time .Minute ), time .Millisecond )
409
412
require .NoError (t , err )
410
413
t .Cleanup (cancel )
411
414
0 commit comments