forked from orgzly-revived/orgzly-android-revived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply "retry rule" in MiscTest and NoteFragmentTest
MiscTest.fragmentTest() is insanely flaky, and it already has sleeps in many places since way back. Sometimes those sleeps just aren't enough, but increasing them would mean slowing everything down a lot. A retry rule is the only working solution I have found. NoteFragmentTest.testContentLineCountUpdatedOnNoteUpdate() is also just too damn flaky, and I cannot understand where the problem is. It just seems that, sometimes, onRecyclerViewItem() will not work, and waiting for the right ID does not help.
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/src/androidTest/java/com/orgzly/android/RetryTestRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.orgzly.android | ||
|
||
import android.util.Log | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
/** | ||
* Retry test rule used to retry test that failed. Retry failed test 3 times | ||
*/ | ||
class RetryTestRule(val retryCount: Int = 3) : TestRule { | ||
|
||
private val TAG = RetryTestRule::class.java.simpleName | ||
|
||
override fun apply(base: Statement, description: Description): Statement { | ||
return statement(base, description) | ||
} | ||
|
||
private fun statement(base: Statement, description: Description): Statement { | ||
return object : Statement() { | ||
@Throws(Throwable::class) | ||
override fun evaluate() { | ||
var caughtThrowable: Throwable? = null | ||
|
||
// implement retry logic here | ||
for (i in 0 until retryCount) { | ||
try { | ||
base.evaluate() | ||
return | ||
} catch (t: Throwable) { | ||
caughtThrowable = t | ||
Log.e(TAG, description.displayName + ": run " + (i + 1) + " failed") | ||
} | ||
} | ||
|
||
Log.e(TAG, description.displayName + ": giving up after " + retryCount + " failures") | ||
throw caughtThrowable!! | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters