Skip to content

Commit

Permalink
status: fix TestTenantStatusAPI test
Browse files Browse the repository at this point in the history
Previously, this test would use a single connection, cancel it, and
then use the connection to verify the cancellation.

The test is adjusted here to use two separate sessions, one to cancel
for testing, and another to observe the cancellation.

Resolves: cockroachdb#125404
Epic: None

Release note: None
  • Loading branch information
dhartunian committed Jul 1, 2024
1 parent 0d30d05 commit 7d4d517
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/ccl/serverccl/statusccl/tenant_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,16 @@ func selectClusterSessionIDs(t *testing.T, conn *sqlutils.SQLRunner) []string {

func testTenantStatusCancelSession(t *testing.T, helper serverccl.TenantTestHelper) {
// Open a SQL session on tenant SQL pod 0.
sqlPod0 := helper.TestCluster().TenantConn(0)
sqlPod0.Exec(t, "SELECT 1")
ctx := context.Background()
// Open two different SQL sessions on tenant SQL pod 0.
sqlPod0 := helper.TestCluster().TenantDB(0)
sqlPod0SessionToCancel, err := sqlPod0.Conn(ctx)
require.NoError(t, err)
sqlPod0SessionForIntrospection, err := sqlPod0.Conn(ctx)
require.NoError(t, err)
_, err = sqlPod0SessionToCancel.ExecContext(ctx, "SELECT 1")
require.NoError(t, err)
introspectionRunner := sqlutils.MakeSQLRunner(sqlPod0SessionForIntrospection)

// See the session over HTTP on tenant SQL pod 1.
httpPod1 := helper.TestCluster().TenantAdminHTTPClient(t, 1)
Expand All @@ -1122,7 +1130,7 @@ func testTenantStatusCancelSession(t *testing.T, helper serverccl.TenantTestHelp
// See the session over SQL on tenant SQL pod 0.
sessionID := hex.EncodeToString(session.ID)
require.Eventually(t, func() bool {
return strings.Contains(strings.Join(selectClusterSessionIDs(t, sqlPod0), ","), sessionID)
return strings.Contains(strings.Join(selectClusterSessionIDs(t, introspectionRunner), ","), sessionID)
}, 5*time.Second, 100*time.Millisecond)

// Cancel the session over HTTP from tenant SQL pod 1.
Expand All @@ -1134,7 +1142,7 @@ func testTenantStatusCancelSession(t *testing.T, helper serverccl.TenantTestHelp
// No longer see the session over SQL from tenant SQL pod 0.
// (The SQL client maintains an internal connection pool and automatically reconnects.)
require.Eventually(t, func() bool {
return !strings.Contains(strings.Join(selectClusterSessionIDs(t, sqlPod0), ","), sessionID)
return !strings.Contains(strings.Join(selectClusterSessionIDs(t, introspectionRunner), ","), sessionID)
}, 5*time.Second, 100*time.Millisecond)

// Attempt to cancel the session again over HTTP from tenant SQL pod 1, so that we can see the error message.
Expand Down

0 comments on commit 7d4d517

Please sign in to comment.