Skip to content

Commit

Permalink
Bug fix: Use target tablet from health stats cache when checking repl…
Browse files Browse the repository at this point in the history
…ication status (vitessio#14436) (#128)

Signed-off-by: Austen Lacy <[email protected]>
Co-authored-by: Austen Lacy <[email protected]>
(cherry picked from commit f757ff2)
  • Loading branch information
austenLacy authored and shivnagarajan committed May 14, 2024
1 parent 7630767 commit 20ee565
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions go/test/endtoend/tabletgateway/vtgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,34 @@ func TestVtgateReplicationStatusCheckWithTabletTypeChange(t *testing.T) {
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))
}

func TestVtgateReplicationStatusCheckWithTabletTypeChange(t *testing.T) {
defer cluster.PanicHandler(t)
// Healthcheck interval on tablet is set to 1s, so sleep for 2s
time.Sleep(2 * time.Second)
verifyVtgateVariables(t, clusterInstance.VtgateProcess.VerifyURL)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

// Only returns rows for REPLICA and RDONLY tablets -- so should be 2 of them
qr := utils.Exec(t, conn, "show vitess_replication_status like '%'")
expectNumRows := 2
numRows := len(qr.Rows)
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))

// change the RDONLY tablet to SPARE
rdOnlyTablet := clusterInstance.Keyspaces[0].Shards[0].Rdonly()
err = clusterInstance.VtctlclientChangeTabletType(rdOnlyTablet, topodata.TabletType_SPARE)
require.NoError(t, err)

// Only returns rows for REPLICA and RDONLY tablets -- so should be 1 of them since we updated 1 to spare
qr = utils.Exec(t, conn, "show vitess_replication_status like '%'")
expectNumRows = 1
numRows = len(qr.Rows)
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))
}

func verifyVtgateVariables(t *testing.T, url string) {
resp, err := http.Get(url)
require.NoError(t, err)
Expand Down

0 comments on commit 20ee565

Please sign in to comment.