Skip to content

Commit 5c7b775

Browse files
committed
Update in test for Bug#96900 (30355150).
1 parent e1169ee commit 5c7b775

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/test/java/testsuite/regression/StatementRegressionTest.java

+27-18
Original file line numberDiff line numberDiff line change
@@ -11906,38 +11906,45 @@ public void testBug85223() throws Exception {
1190611906
*/
1190711907
@Test
1190811908
public void testBug96900() throws Exception {
11909-
assumeTrue(versionMeetsMinimum(5, 6), "MySQL 5.6+ is required to run this test.");
11909+
assumeTrue(versionMeetsMinimum(5, 7), "MySQL 5.7+ is required to run this test.");
11910+
11911+
Supplier<Integer> sessionCount = () -> {
11912+
try {
11913+
this.stmt.execute("FLUSH STATUS");
11914+
this.rs = this.stmt.executeQuery("SHOW STATUS LIKE 'threads_connected'");
11915+
this.rs.next();
11916+
return this.rs.getInt(2);
11917+
} catch (SQLException e) {
11918+
throw new RuntimeException(e.getMessage(), e);
11919+
}
11920+
};
11921+
11922+
int initialSessionCount = sessionCount.get();
1191011923

1191111924
Properties props = new Properties();
1191211925
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
1191311926
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11914-
props.setProperty(PropertyKey.connectionAttributes.getKeyName(), "testBug96900:1");
1191511927

11916-
Connection con = getConnectionWithProps(props);
11917-
Statement st = con.createStatement();
11928+
Connection testConn = getConnectionWithProps(props);
11929+
Statement testStmt = testConn.createStatement();
11930+
1191811931
new Thread(() -> {
1191911932
try {
11920-
st.executeQuery("SELECT SLEEP(600)");
11933+
testStmt.executeQuery("SELECT SLEEP(600)");
1192111934
} catch (Throwable e) {
1192211935
e.printStackTrace();
1192311936
}
1192411937
}).start();
1192511938

11926-
String attCountQuery = "SELECT COUNT(*) FROM performance_schema.session_connect_attrs WHERE attr_name = 'testBug96900'";
11927-
11928-
this.rs = this.stmt.executeQuery(attCountQuery);
11929-
this.rs.next();
11930-
assertEquals(1, this.rs.getInt(1));
11939+
// The difference between the `initialSessionCount` and the current session count would be greater than one if connections external to this test are
11940+
// created in between. Chances for this to happen in a controlled or development environment are very low and can be neglected.
11941+
assertEquals(1, sessionCount.get() - initialSessionCount);
1193111942

11932-
st.cancel();
11933-
this.rs = this.stmt.executeQuery(attCountQuery);
11934-
this.rs.next();
11935-
assertEquals(1, this.rs.getInt(1));
11943+
testStmt.cancel();
11944+
assertEquals(1, sessionCount.get() - initialSessionCount);
1193611945

11937-
con.close();
11938-
this.rs = this.stmt.executeQuery(attCountQuery);
11939-
this.rs.next();
11940-
assertEquals(0, this.rs.getInt(1));
11946+
testConn.close();
11947+
assertEquals(0, sessionCount.get() - initialSessionCount);
1194111948
}
1194211949

1194311950
/**
@@ -11947,6 +11954,8 @@ public void testBug96900() throws Exception {
1194711954
*/
1194811955
@Test
1194911956
public void testBug99260() throws Exception {
11957+
assumeTrue(versionMeetsMinimum(5, 7), "MySQL 5.7+ is required to run this test.");
11958+
1195011959
Supplier<Integer> sessionCount = () -> {
1195111960
try {
1195211961
this.stmt.execute("FLUSH STATUS");

0 commit comments

Comments
 (0)