@@ -432,7 +432,9 @@ func TestUpdateConnectionPool(t *testing.T) {
432432 },
433433 }
434434
435- pool .Update (initConnList ())
435+ if err := pool .Update (initConnList ()); err != nil {
436+ t .Fatalf ("Unexpected error: %s" , err )
437+ }
436438 if len (pool .dead ) != 0 {
437439 t .Errorf ("Expected no dead connections, got: %s" , pool .dead )
438440 }
@@ -450,7 +452,9 @@ func TestUpdateConnectionPool(t *testing.T) {
450452 {URL : & url.URL {Scheme : "http" , Host : "bar1" }},
451453 }
452454
453- pool .Update (updatedConnections )
455+ if err := pool .Update (updatedConnections ); err != nil {
456+ t .Fatalf ("Unexpected error: %s" , err )
457+ }
454458
455459 fmt .Println (pool .live )
456460 fmt .Println (pool .dead )
@@ -467,11 +471,13 @@ func TestUpdateConnectionPool(t *testing.T) {
467471 pool .live = append (pool .live , & conns [i ])
468472 }
469473
470- tmp := []* Connection {}
474+ var tmp []* Connection
471475 for i := 0 ; i < len (conns ); i ++ {
472476 tmp = append (tmp , & conns [i ])
473477 }
474- pool .Update (tmp )
478+ if err := pool .Update (tmp ); err != nil {
479+ t .Fatalf ("Unexpected error: %s" , err )
480+ }
475481
476482 if len (pool .live ) != len (tmp ) {
477483 t .Errorf ("Invalid number of connections: %d" , len (pool .live ))
@@ -494,29 +500,44 @@ func TestUpdateConnectionPool(t *testing.T) {
494500 {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
495501 }
496502 err = cp .Update (connections )
503+ if err != nil {
504+ t .Errorf ("First Update() returned an error: %v" , err )
505+ }
497506 if len (cp .live ) != 2 {
498507 t .Errorf ("Expected only two live connection after update" )
499508 }
500509
501510 // foo1 fails
502- cp .OnFailure (cp .live [0 ])
511+ err = cp .OnFailure (cp .live [0 ])
512+ if err != nil {
513+ t .Errorf ("OnFailure() returned an error: %v" , err )
514+ }
503515 // we update the connexion, nothing should move
504516 err = cp .Update (connections )
517+ if err != nil {
518+ t .Errorf ("Second Update() returned an error: %v" , err )
519+ }
505520 if len (cp .live ) != 1 {
506521 t .Errorf ("Expected no connections to be added to lists" )
507522 }
508523
509524 // Test adding a new connection that's not already present
510525 connections = append (connections , & Connection {URL : & url.URL {Scheme : "http" , Host : "foo12" }})
511526 err = cp .Update (connections )
527+ if err != nil {
528+ t .Errorf ("Third Update() returned an error: %v" , err )
529+ }
512530 if len (cp .live ) != 2 {
513531 t .Errorf ("Expected the new connection to be added to live list" )
514532 }
515- cp .resurrect (cp .dead [0 ], false )
533+
534+ if err := cp .resurrect (cp .dead [0 ], false ); err != nil {
535+ t .Fatalf ("Unexpected error: %s" , err )
536+ }
516537
517538 // Test updating with an empty list of connections
518539 connections = []* Connection {}
519- err = cp .Update (connections )
540+ _ = cp .Update (connections )
520541 if len (cp .live ) != 3 {
521542 t .Errorf ("Expected connections to be untouched after empty update" )
522543 }
@@ -542,7 +563,9 @@ func TestUpdateConnectionPool(t *testing.T) {
542563 }
543564
544565 // Update happens between Next and OnFailure
545- cp .Update (connections )
566+ if err := cp .Update (connections ); err != nil {
567+ t .Errorf ("unexpected error: %s" , err )
568+ }
546569
547570 // conn fails, doesn't exist in live list anymore
548571 err = cp .OnFailure (conn )
@@ -560,19 +583,19 @@ func TestCloseConnectionPool(t *testing.T) {
560583 t .Run ("CloseConnectionPool" , func (t * testing.T ) {
561584 pool := & statusConnectionPool {
562585 live : []* Connection {
563- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
564- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
586+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
587+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
565588 },
566589 selector : & roundRobinSelector {curr : - 1 },
567590 closeC : make (chan struct {}),
568591 }
569592
570- err := pool .Close (t . Context ())
593+ err := pool .Close (context . Background ())
571594 if err != nil {
572595 t .Errorf ("Close() returned an error: %v" , err )
573596 }
574597
575- err = pool .Close (t . Context ())
598+ err = pool .Close (context . Background ())
576599 if err == nil {
577600 t .Errorf ("Second call to Close() should return an error" )
578601 } else if ! strings .Contains (err .Error (), "already closed" ) {
@@ -583,8 +606,8 @@ func TestCloseConnectionPool(t *testing.T) {
583606 t .Run ("CloseConnectionPool isClosed" , func (t * testing.T ) {
584607 pool := & statusConnectionPool {
585608 live : []* Connection {
586- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
587- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
609+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
610+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
588611 },
589612 selector : & roundRobinSelector {curr : - 1 },
590613 closeC : make (chan struct {}),
@@ -593,7 +616,7 @@ func TestCloseConnectionPool(t *testing.T) {
593616 if pool .isClosed () {
594617 t .Errorf ("isClosed() returned true before closing" )
595618 }
596- err := pool .Close (t . Context ())
619+ err := pool .Close (context . Background ())
597620 if err != nil {
598621 t .Errorf ("Close() returned an error: %v" , err )
599622 }
@@ -607,8 +630,8 @@ func TestCloseConnectionPool(t *testing.T) {
607630
608631 pool := & statusConnectionPool {
609632 live : []* Connection {
610- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
611- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
633+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
634+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
612635 },
613636 dead : []* Connection {
614637 deadConn ,
@@ -619,7 +642,7 @@ func TestCloseConnectionPool(t *testing.T) {
619642
620643 pool .scheduleResurrect (deadConn )
621644
622- err := pool .Close (t . Context ())
645+ err := pool .Close (context . Background ())
623646 if err != nil {
624647 t .Errorf ("Close() returned an error: %v" , err )
625648 }
@@ -636,13 +659,13 @@ func TestCloseConnectionPool(t *testing.T) {
636659 t .Run ("CloseConnectionPool nil context" , func (t * testing.T ) {
637660 pool := & statusConnectionPool {
638661 live : []* Connection {
639- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
640- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
662+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
663+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
641664 },
642665 selector : & roundRobinSelector {curr : - 1 },
643666 closeC : make (chan struct {}),
644667 }
645- err := pool .Close (nil )
668+ err := pool .Close (nil ) //nolint:staticcheck
646669 if err != nil {
647670 t .Errorf ("Close() returned an error: %v" , err )
648671 }
@@ -651,16 +674,16 @@ func TestCloseConnectionPool(t *testing.T) {
651674 t .Run ("CloseConnectionPool should timeout" , func (t * testing.T ) {
652675 pool := & statusConnectionPool {
653676 live : []* Connection {
654- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
655- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
677+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
678+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
656679 },
657680 selector : & roundRobinSelector {curr : - 1 },
658681 closeC : make (chan struct {}),
659682 }
660683 // Add to waitgroup that will never be resolved
661684 pool .resurrectWaitGroup .Add (1 )
662685
663- ctx , cancel := context .WithTimeout (t . Context (), time .Millisecond )
686+ ctx , cancel := context .WithTimeout (context . Background (), time .Millisecond )
664687 defer cancel ()
665688
666689 err := pool .Close (ctx )
@@ -672,14 +695,14 @@ func TestCloseConnectionPool(t *testing.T) {
672695 t .Run ("CloseConnectionPool Next() should error if closed" , func (t * testing.T ) {
673696 pool := & statusConnectionPool {
674697 live : []* Connection {
675- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
676- & Connection {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
698+ {URL : & url.URL {Scheme : "http" , Host : "foo1" }},
699+ {URL : & url.URL {Scheme : "http" , Host : "foo2" }},
677700 },
678701 selector : & roundRobinSelector {curr : - 1 },
679702 closeC : make (chan struct {}),
680703 }
681704
682- err := pool .Close (t . Context ())
705+ err := pool .Close (context . Background ())
683706 if err != nil {
684707 t .Errorf ("Close() returned an error: %v" , err )
685708 }
0 commit comments