Skip to content

Commit

Permalink
Update in test for Bug#96900 (30355150).
Browse files Browse the repository at this point in the history
  • Loading branch information
fjssilva committed Nov 26, 2021
1 parent e1169ee commit 5c7b775
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11906,38 +11906,45 @@ public void testBug85223() throws Exception {
*/
@Test
public void testBug96900() throws Exception {
assumeTrue(versionMeetsMinimum(5, 6), "MySQL 5.6+ is required to run this test.");
assumeTrue(versionMeetsMinimum(5, 7), "MySQL 5.7+ is required to run this test.");

Supplier<Integer> sessionCount = () -> {
try {
this.stmt.execute("FLUSH STATUS");
this.rs = this.stmt.executeQuery("SHOW STATUS LIKE 'threads_connected'");
this.rs.next();
return this.rs.getInt(2);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
};

int initialSessionCount = sessionCount.get();

Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.connectionAttributes.getKeyName(), "testBug96900:1");

Connection con = getConnectionWithProps(props);
Statement st = con.createStatement();
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();

new Thread(() -> {
try {
st.executeQuery("SELECT SLEEP(600)");
testStmt.executeQuery("SELECT SLEEP(600)");
} catch (Throwable e) {
e.printStackTrace();
}
}).start();

String attCountQuery = "SELECT COUNT(*) FROM performance_schema.session_connect_attrs WHERE attr_name = 'testBug96900'";

this.rs = this.stmt.executeQuery(attCountQuery);
this.rs.next();
assertEquals(1, this.rs.getInt(1));
// The difference between the `initialSessionCount` and the current session count would be greater than one if connections external to this test are
// created in between. Chances for this to happen in a controlled or development environment are very low and can be neglected.
assertEquals(1, sessionCount.get() - initialSessionCount);

st.cancel();
this.rs = this.stmt.executeQuery(attCountQuery);
this.rs.next();
assertEquals(1, this.rs.getInt(1));
testStmt.cancel();
assertEquals(1, sessionCount.get() - initialSessionCount);

con.close();
this.rs = this.stmt.executeQuery(attCountQuery);
this.rs.next();
assertEquals(0, this.rs.getInt(1));
testConn.close();
assertEquals(0, sessionCount.get() - initialSessionCount);
}

/**
Expand All @@ -11947,6 +11954,8 @@ public void testBug96900() throws Exception {
*/
@Test
public void testBug99260() throws Exception {
assumeTrue(versionMeetsMinimum(5, 7), "MySQL 5.7+ is required to run this test.");

Supplier<Integer> sessionCount = () -> {
try {
this.stmt.execute("FLUSH STATUS");
Expand Down

0 comments on commit 5c7b775

Please sign in to comment.