Skip to content

Commit

Permalink
Fixed ordered tests in "CorruptedDatabaseTest"
Browse files Browse the repository at this point in the history
Fixed "testOpenVersion0DatabaseVerifyStreamAccessed":
"CorruptedDatabaseTest.kt:103" calls "RoomDatabase.compileStatement", which contains two calls to "writableDatabase" that were not previously accounted for.

Fixed "testOpenDatabaseWithRecovery":
The assertion in "CorruptedDatabaseTest.kt:129" is called by "PatchedCallback.onCreate" in "DatabaseOpenHelperFactory.kt:61", which is called by "FrameworkSQLiteOpenHelper.OpenHelper.innerGetDatabase". "PatchedCallback.onCreate" then calls "DatabaseCallback.onCreate", which then throws the "UnsupportedOperationException" ("DatabaseModule.kt:137") expected by the assertion in "CorruptedDatabaseTest.kt:123". However, it was not previously taken into account that "FrameworkSQLiteOpenHelper.OpenHelper.innerGetDatabase" discards the first thrown exception and tries again, which results in a second call to "PatchedCallback.onCreate" and therefore a second call to the assertion in "CorruptedDatabaseTest.kt:129" before the assertion in "CorruptedDatabaseTest.kt:123" is reached.
  • Loading branch information
JaniruTEC committed Oct 20, 2024
1 parent 6ed2b42 commit 4951ebb
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CorruptedDatabaseTest {
}
val listener = object : InterceptorOpenHelperListener {
override fun onWritableDatabaseCalled() {
assertOrder(order, 1)
assertOrder(order, 1, 3, 4)
}
}

Expand All @@ -104,7 +104,7 @@ class CorruptedDatabaseTest {
require(statement.simpleQueryForLong() == 1L)
}
}, finallyBlock = CryptomatorDatabase::close)
assertOrder(order, 3)
assertOrder(order, 5)
}

@Test
Expand All @@ -120,13 +120,13 @@ class CorruptedDatabaseTest {
}

override fun onWritableDatabaseThrew(exc: Exception): Exception {
assertOrder(order, 3)
assertOrder(order, 4)
assertThat(exc, instanceOf(UnsupportedOperationException::class.java))
return WrappedException(exc)
}
}
val openHelperFactory = openHelperFactory {
assertOrder(order, 2)
assertOrder(order, 2, 3)
}

createVersion0Database(context, TEST_DB)
Expand All @@ -143,7 +143,7 @@ class CorruptedDatabaseTest {
}.also {
assertThat(it.cause, instanceOf(UnsupportedOperationException::class.java))
}
assertOrder(order, 4)
assertOrder(order, 5)
}
}

Expand Down

0 comments on commit 4951ebb

Please sign in to comment.