Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: EXPOSED-191 Flaky Oracle test on TC build #2098

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ open class InsertStatement<Key : Any>(
*/
fun <T> getOrNull(column: Column<T>): T? = resultedValues?.firstOrNull()?.getOrNull(column)

@Suppress("NestedBlockDepth", "ComplexMethod")
@Suppress("NestedBlockDepth", "ComplexMethod", "TooGenericExceptionCaught")
private fun processResults(rs: ResultSet?, inserted: Int): List<ResultRow> {
val autoGeneratedKeys = arrayListOf<MutableMap<Column<*>, Any?>>()

Expand All @@ -69,7 +69,23 @@ open class InsertStatement<Key : Any>(
if (firstAutoIncColumn != null || returnedColumns.isNotEmpty()) {
while (rs?.next() == true) {
val returnedValues = returnedColumns.associateTo(mutableMapOf()) { it.first to rs.getObject(it.second) }
if (returnedValues.isEmpty() && firstAutoIncColumn != null) returnedValues[firstAutoIncColumn] = rs.getObject(1)
if (returnedValues.isEmpty() && firstAutoIncColumn != null) {
try {
returnedValues[firstAutoIncColumn] = rs.getObject(1)
} catch (e: ArrayIndexOutOfBoundsException) {
// EXPOSED-191 Flaky Oracle test on TC build
// this try/catch should help to get information about the flaky test.
// try/catch can be safely removed after the fixing the issue.
// TooGenericExceptionCaught suppress also can be removed

exposedLogger.error(
"ArrayIndexOutOfBoundsException on processResults. " +
"Table: ${table.tableName}, firstAutoIncColumn: ${firstAutoIncColumn.name}, inserted: $inserted",
e
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the culprit statement itself also be logged? this.prepareSQL(TransactionManager.current(), prepared = true)
Since there seem to be many reports of this exception with prepared statements and the amount of parameters (or maybe the set fetch size).

Another option could be to enable debug mode in the test's transaction and log the statements as they are executed there, but because the test uses DAO, the commit() wouldn't allow us to single out which statement is failing.

And if the logs don't give us enough info, I'd question why commit() is even being used.
The SELECT COUNT should trigger a full flush before all the asserts are run and the test should pass without it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I didn't know about the TransactionManager.current() options)

Added logging of sql that failed and logging of columns that should taken from the result set.

Also added stdout logger to the test.

throw e
}
}
autoGeneratedKeys.add(returnedValues)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class EntityCache(private val transaction: Transaction) {
}
}

@Suppress("TooGenericExceptionCaught")
internal fun flushInserts(table: IdTable<*>) {
var toFlush: List<Entity<*>> = inserts.remove(table)?.toList().orEmpty()
while (toFlush.isNotEmpty()) {
Expand All @@ -236,12 +237,26 @@ class EntityCache(private val transaction: Transaction) {
}
}
toFlush = partition.first
val ids = executeAsPartOfEntityLifecycle {
table.batchInsert(toFlush) { entry ->
for ((c, v) in entry.writeValues) {
this[c] = v
val ids = try {
executeAsPartOfEntityLifecycle {
table.batchInsert(toFlush) { entry ->
for ((c, v) in entry.writeValues) {
this[c] = v
}
}
}
} catch (e: ArrayIndexOutOfBoundsException) {
obabichevjb marked this conversation as resolved.
Show resolved Hide resolved
// EXPOSED-191 Flaky Oracle test on TC build
// this try/catch should help to get information about the flaky test.
// try/catch can be safely removed after the fixing the issue
// TooGenericExceptionCaught suppress also can be removed
val toFlushString = toFlush.joinToString("; ") {
entry ->
entry.writeValues.map { writeValue -> "${writeValue.key.name}=${writeValue.value}" }.joinToString { ", " }
}

exposedLogger.error("ArrayIndexOutOfBoundsException on attempt to make flush inserts. Table: ${table.tableName}, entries: ($toFlushString)", e)
throw e
}

for ((entry, genValues) in toFlush.zip(ids)) {
Expand Down
Loading