@@ -29,6 +29,7 @@ import (
29
29
"vitess.io/vitess/go/vt/logutil"
30
30
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
31
31
"vitess.io/vitess/go/vt/topo"
32
+ "vitess.io/vitess/go/vt/topo/faketopo"
32
33
"vitess.io/vitess/go/vt/topo/memorytopo"
33
34
)
34
35
@@ -614,3 +615,62 @@ func TestFilterByKeypsaceSkipsIgnoredTablets(t *testing.T) {
614
615
615
616
tw .Stop ()
616
617
}
618
+
619
+ func TestGetTabletErrorDoesNotRemoveFromHealthcheck (t * testing.T ) {
620
+ factory := faketopo .NewFakeTopoFactory ()
621
+ // add cell to the factory. This returns a fake connection which we will use to set the get and update errors as we require.
622
+ fakeConn := factory .AddCell ("aa" )
623
+
624
+ ts := faketopo .NewFakeTopoServer (factory )
625
+ if err := ts .CreateCellInfo (context .Background (), "aa" , & topodatapb.CellInfo {}); err != nil {
626
+ t .Fatalf ("CreateCellInfo failed: %v" , err )
627
+ }
628
+
629
+ fhc := NewFakeHealthCheck (nil )
630
+ topologyWatcherOperations .ZeroAll ()
631
+ counts := topologyWatcherOperations .Counts ()
632
+ tw := NewCellTabletsWatcher (context .Background (), ts , fhc , nil , "aa" , 10 * time .Minute , true , 5 )
633
+
634
+ counts = checkOpCounts (t , counts , map [string ]int64 {})
635
+ checkChecksum (t , tw , 0 )
636
+
637
+ // Add a tablet to the topology.
638
+ tablet := & topodatapb.Tablet {
639
+ Alias : & topodatapb.TabletAlias {
640
+ Cell : "aa" ,
641
+ Uid : 0 ,
642
+ },
643
+ Hostname : "host1" ,
644
+ PortMap : map [string ]int32 {
645
+ "vt" : 123 ,
646
+ },
647
+ Keyspace : "keyspace" ,
648
+ Shard : "shard" ,
649
+ }
650
+ if err := ts .CreateTablet (context .Background (), tablet ); err != nil {
651
+ t .Fatalf ("CreateTablet failed: %v" , err )
652
+ }
653
+ tw .loadTablets ()
654
+ counts = checkOpCounts (t , counts , map [string ]int64 {"ListTablets" : 1 , "GetTablet" : 1 , "AddTablet" : 1 })
655
+ checkChecksum (t , tw , 3238442862 )
656
+
657
+ // Check the tablet is returned by GetAllTablets().
658
+ allTablets := fhc .GetAllTablets ()
659
+ key := TabletToMapKey (tablet )
660
+ if _ , ok := allTablets [key ]; ! ok || len (allTablets ) != 1 || ! proto .Equal (allTablets [key ], tablet ) {
661
+ t .Errorf ("fhc.GetAllTablets() = %+v; want %+v" , allTablets , tablet )
662
+ }
663
+
664
+ // Force the next topo Get call to return an error (the ListDir call for the tablet aliases will still succeed)
665
+ fakeConn .AddGetError (true )
666
+
667
+ tw .loadTablets ()
668
+ checkOpCounts (t , counts , map [string ]int64 {"ListTablets" : 1 , "GetTablet" : 1 })
669
+ checkChecksum (t , tw , 3238442862 )
670
+
671
+ // Check the tablet is still returned by GetAllTablets().
672
+ allTablets2 := fhc .GetAllTablets ()
673
+ if _ , ok := allTablets2 [key ]; ! ok || len (allTablets2 ) != 1 || ! proto .Equal (allTablets2 [key ], tablet ) {
674
+ t .Errorf ("fhc.GetAllTablets() = %+v; want %+v" , allTablets2 , tablet )
675
+ }
676
+ }
0 commit comments