Skip to content

Commit

Permalink
Poll session count instead of sleeping (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyprime committed Feb 11, 2022
1 parent c76c34a commit b3d9b51
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4145,22 +4145,29 @@ class EndToEndTests(readOpts: Map[String, String], writeOpts: Map[String, String
val dfRead: DataFrame = spark.read.format("com.vertica.spark.datasource.VerticaSource").options(readOpts + ("table" -> tableName)).load()
assert(dfRead.count() == 3)
}
// Ensure operations have time to complete and cleanup
Thread.sleep(5000)

val stmt = conn.createStatement()
val query = "SELECT COUNT(*) FROM v_monitor.sessions;"
try {
val rs = stmt.executeQuery(query)
assert(rs.next)
// Expect a single session for the session count query itself
// Note that this can fail if you are connected to vsql or performing other operations on the DB at the same time as these tests
assert(rs.getInt(1) == 1)
} catch {
case err : Exception => fail(err)
} finally {
stmt.close()
// Poll sessions until they have cleaned up (or until we give up)
var success: Boolean = false
var i: Int = 0
while (!success || i < 10) {
val stmt = conn.createStatement()
val query = "SELECT COUNT(*) FROM v_monitor.sessions;"
try {
val rs = stmt.executeQuery(query)
rs.next
// Expect a single session for the session count query itself
// Note that this can fail if you are connected to vsql or performing other operations on the DB at the same time as these tests
success = (rs.getInt(1) == 1)
} catch {
case err : Exception => fail(err)
} finally {
stmt.close()
}
println("Unexpected session count, trying again - iteration " + i)
i += 1
Thread.sleep(1000)
}
assert(success)

TestUtils.dropTable(conn, tableName)
}
Expand Down

0 comments on commit b3d9b51

Please sign in to comment.