@@ -11906,38 +11906,45 @@ public void testBug85223() throws Exception {
11906
11906
*/
11907
11907
@Test
11908
11908
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();
11910
11923
11911
11924
Properties props = new Properties();
11912
11925
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11913
11926
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11914
- props.setProperty(PropertyKey.connectionAttributes.getKeyName(), "testBug96900:1");
11915
11927
11916
- Connection con = getConnectionWithProps(props);
11917
- Statement st = con.createStatement();
11928
+ Connection testConn = getConnectionWithProps(props);
11929
+ Statement testStmt = testConn.createStatement();
11930
+
11918
11931
new Thread(() -> {
11919
11932
try {
11920
- st .executeQuery("SELECT SLEEP(600)");
11933
+ testStmt .executeQuery("SELECT SLEEP(600)");
11921
11934
} catch (Throwable e) {
11922
11935
e.printStackTrace();
11923
11936
}
11924
11937
}).start();
11925
11938
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);
11931
11942
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);
11936
11945
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);
11941
11948
}
11942
11949
11943
11950
/**
@@ -11947,6 +11954,8 @@ public void testBug96900() throws Exception {
11947
11954
*/
11948
11955
@Test
11949
11956
public void testBug99260() throws Exception {
11957
+ assumeTrue(versionMeetsMinimum(5, 7), "MySQL 5.7+ is required to run this test.");
11958
+
11950
11959
Supplier<Integer> sessionCount = () -> {
11951
11960
try {
11952
11961
this.stmt.execute("FLUSH STATUS");
0 commit comments