17
17
package collector
18
18
19
19
import (
20
- "context"
21
20
"errors"
22
21
"fmt"
23
22
"io"
@@ -75,7 +74,7 @@ func TestAddRemove(t *testing.T) {
75
74
}
76
75
77
76
func TestRun (t * testing.T ) {
78
- ctx := context . Background ()
77
+ ctx := t . Context ()
79
78
c := New (nil , gate .New (0 ))
80
79
c .runOnce (ctx , time .Now ())
81
80
@@ -307,7 +306,7 @@ func TestMarkInactive(t *testing.T) {
307
306
t1 := t0 .Add (10 * time .Second )
308
307
t2 := t1 .Add (10 * time .Second )
309
308
310
- err := c .RunGather (context . Background (), t0 )
309
+ err := c .RunGather (t . Context (), t0 )
311
310
if err != nil {
312
311
t .Fatalf ("Unexpected c.RunGather() error: %v" , err )
313
312
}
@@ -346,7 +345,7 @@ func TestMarkInactive(t *testing.T) {
346
345
347
346
input2 .tag = "I2" // Tags have changed
348
347
349
- err = c .RunGather (context . Background (), t1 )
348
+ err = c .RunGather (t . Context (), t1 )
350
349
if err != nil {
351
350
t .Fatalf ("Unexpected c.RunGather() error: %v" , err )
352
351
}
@@ -385,7 +384,7 @@ func TestMarkInactive(t *testing.T) {
385
384
386
385
input2bis .fields ["f" ] = 22.22
387
386
388
- err = c .RunGather (context . Background (), t2 )
387
+ err = c .RunGather (t . Context (), t2 )
389
388
if err != nil {
390
389
t .Fatalf ("Unexpected c.RunGather() error: %v" , err )
391
390
}
@@ -511,7 +510,7 @@ func TestMarkInactiveWhileDroppingInput(t *testing.T) {
511
510
wg .Done ()
512
511
}()
513
512
514
- err = c .RunGather (context . Background (), time .Now ())
513
+ err = c .RunGather (t . Context (), time .Now ())
515
514
if err != nil {
516
515
t .Fatalf ("Unexpected c.RunGather() error: %v" , err )
517
516
}
@@ -547,7 +546,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
547
546
t1 := t0 .Add (10 * time .Second )
548
547
t2 := t1 .Add (keepMetricBecauseOfGatherErrorGraceDelay )
549
548
550
- err = c .RunGather (context . Background (), t0 )
549
+ err = c .RunGather (t . Context (), t0 )
551
550
if err != nil {
552
551
t .Fatal ("Gathering failed:" , err )
553
552
}
@@ -570,7 +569,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
570
569
input .fields = map [string ]float64 {"f2" : 0.22 , "f3" : 33 } // no value for f1
571
570
input .retErr = io .ErrUnexpectedEOF // perhaps because of this error
572
571
573
- err = c .RunGather (context . Background (), t1 )
572
+ err = c .RunGather (t . Context (), t1 )
574
573
if err != nil {
575
574
t .Fatal ("Gathering failed:" , err )
576
575
}
@@ -588,7 +587,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
588
587
input .fields = map [string ]float64 {"f3" : 3 , "f4" : 4.4 } // no more value for f2 neither; a new metric appears;
589
588
// the error is still present
590
589
591
- err = c .RunGather (context . Background (), t2 )
590
+ err = c .RunGather (t . Context (), t2 )
592
591
if err != nil {
593
592
t .Fatal ("Gathering failed:" , err )
594
593
}
@@ -640,7 +639,7 @@ func TestErrorHandling(t *testing.T) {
640
639
}
641
640
}
642
641
643
- err := c .RunGather (context . Background (), time .Now ())
642
+ err := c .RunGather (t . Context (), time .Now ())
644
643
expectedErrors := []error {os .ErrPermission , os .ErrPermission , io .ErrUnexpectedEOF }
645
644
646
645
for _ , expectedErr := range expectedErrors {
0 commit comments