Skip to content

Commit

Permalink
[#20393][conn-mgr] Enabled testRevokeLoginMidSession test with conn-mgr
Browse files Browse the repository at this point in the history
Summary:
This diff enables `TestPgAuthorization.testRevokeLoginMidSession`  to run with connection manager.

**What this test do**

- Creates a custom role `test_role` with login permission.
- Create a PG session with role `test_role`
- Then Alters the `test_role` to from LOGIN perm to NOLOGIN.
- The existing session created before ALTER command should work while any attempt to create new session should fail.

**Why it was failing with connection manager**

This test was failing flakily with connection manager because in test setup, `ysql_conn_mgr_dowarmup_all_pools_mode` is set to random which we create `ysql_conn_mgr_min_conns_per_db` (default: 3) number of server connections in any pool whenever there is a requirement to create the first backend process in that particular pool. The first backend is created before ALTER ROLE is done at this line.

```
Connection connection2 = getConnectionBuilder().withTServer(1)
          .withUser("test_role").connect();
```

So there one backend created but 3 server connection objects in server pool for this route (yugabyte, test_role). To get server connection for query after ALTER command.

```
        // Open session is still usable, even after the alter.
        statement2.execute("SELECT count(*) FROM pg_class");
```
So there is a probability that there would be an attempt to spawn a new backend but that would fail as login permission is revoked.

**Fix added **

Diff D40621 enabled complete TestPgAuthorization test suite to run with version matching routing. Due to this now the server connection corresponding to the spawned backend will be selected to run the query instead of selecting randomly.

Side fix:

Fixes a debug log in odyssey

```
	od_debug(&instance->logger, "auth backend", client, server,
		 "auth's backend logical client version = %d", server->logical_client_version);
	client->logical_client_version = server->logical_client_version;
```

Test Plan:
Jenkins: enable connection manager, all tests

  ./yb_build.sh release  --enable-ysql-conn-mgr-test --java-test org.yb.pgsql.TestPgAuthorization#testRevokeLoginMidSession -n 50

Reviewers: mkumar, rbarigidad, skumar

Reviewed By: rbarigidad

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D40701
  • Loading branch information
Devansh Saxena committed Dec 17, 2024
1 parent bbb1db7 commit 306b14b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2713,9 +2713,6 @@ public void testCreateSchemaAuthorization() throws Exception {

@Test
public void testRevokeLoginMidSession() throws Exception {
// (DB-12741) Skip this test if running with connection manager.
assumeFalse(BasePgSQLTest.INCORRECT_CONN_STATE_BEHAVIOR, isTestRunningWithConnectionManager());

try (Connection connection1 = getConnectionBuilder().withTServer(0).connect();
Statement statement1 = connection1.createStatement()) {

Expand Down
2 changes: 1 addition & 1 deletion src/odyssey/sources/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@ int yb_auth_via_auth_backend(od_client_t *client)
rc = od_backend_connect(server, "auth backend", NULL,
control_conn_client);
/*Store the client's logical_client_version as auth backend's logical_client_version*/
od_debug(&instance->logger, "auth backend", control_conn_client, server,
od_debug(&instance->logger, "auth backend", client, server,
"auth's backend logical client version = %d", server->logical_client_version);
client->logical_client_version = server->logical_client_version;

Expand Down

0 comments on commit 306b14b

Please sign in to comment.