Optimize WarmUpRule #1310

This PR is made of 2 commits.
The first is just a mass rename in order to spare 1 line of code every time `WarmUpRule` is used.
The second tweaks `WarmUpRule` so that the warmup code is only run once per test class.
This commit is contained in:
Marco Romano 2023-09-13 16:27:32 +02:00 committed by GitHub
commit bdc6cdd12a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 69 additions and 117 deletions

View file

@ -37,8 +37,7 @@ import org.junit.Rule
import org.junit.Test
class RootPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -37,8 +37,7 @@ import org.junit.Test
class LoggedInPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -31,8 +31,7 @@ import org.junit.Test
class AnalyticsOptInPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -30,8 +30,7 @@ import org.junit.Test
class AnalyticsPreferencesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -32,8 +32,7 @@ import org.junit.Test
class AddPeoplePresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var presenter: AddPeoplePresenter

View file

@ -60,8 +60,7 @@ private const val AN_URI_FROM_GALLERY = "content://uri_from_gallery"
@RunWith(RobolectricTestRunner::class)
class ConfigureRoomPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var presenter: ConfigureRoomPresenter

View file

@ -44,8 +44,7 @@ import org.junit.Test
class CreateRoomRootPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var userRepository: FakeUserRepository

View file

@ -33,8 +33,7 @@ import org.junit.Test
class DefaultUserListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val userRepository = FakeUserRepository()

View file

@ -32,8 +32,7 @@ import org.junit.Test
class MigrationScreenPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -39,8 +39,7 @@ import org.junit.Test
class NotificationsOptInPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private var isFinished = false

View file

@ -50,8 +50,7 @@ import org.junit.Rule
import org.junit.Test
class InviteListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -39,8 +39,7 @@ import org.junit.Test
class LeaveRoomPresenterImplTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -42,8 +42,7 @@ import org.junit.Test
class SendLocationPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val permissionsPresenterFake = PermissionsPresenterFake()

View file

@ -35,8 +35,7 @@ import org.junit.Test
class ShowLocationPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val permissionsPresenterFake = PermissionsPresenterFake()

View file

@ -33,8 +33,7 @@ import org.junit.Test
class ChangeServerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -35,8 +35,7 @@ import org.junit.Test
class OidcPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -31,8 +31,7 @@ import org.junit.Test
class ChangeAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -39,8 +39,7 @@ import org.junit.Test
class ConfirmAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -38,8 +38,7 @@ import org.junit.Test
class LoginPasswordPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -38,8 +38,7 @@ import org.junit.Test
class SearchAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -37,8 +37,7 @@ import org.junit.Test
class WaitListPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -32,8 +32,7 @@ import org.junit.Test
class LogoutPreferencePresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -86,8 +86,7 @@ import kotlin.time.Duration.Companion.milliseconds
class MessagesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val mockMediaUrl: Uri = mockk("localMediaUri")

View file

@ -41,8 +41,7 @@ import org.junit.Test
class ActionListPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -43,8 +43,7 @@ import org.junit.Test
class AttachmentsPreviewPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val mediaPreProcessor = FakeMediaPreProcessor()

View file

@ -39,8 +39,7 @@ import org.junit.Test
class ForwardMessagesPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()

View file

@ -44,8 +44,7 @@ private val TESTED_MEDIA_INFO = aFileInfo()
class MediaViewerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()

View file

@ -35,8 +35,7 @@ import org.junit.Test
class ReportMessagePresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -69,8 +69,7 @@ import java.io.File
class MessageComposerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val pickerProvider = FakePickerProvider().apply {

View file

@ -51,8 +51,7 @@ import java.util.Date
class TimelinePresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -33,8 +33,7 @@ import org.junit.Test
class CustomReactionPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val presenter = CustomReactionPresenter(emojibaseProvider = FakeEmojibaseProvider())

View file

@ -37,8 +37,7 @@ import org.junit.Test
class ReactionSummaryPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val aggregatedReaction = anAggregatedReaction(userId = A_USER_ID, key = "👍", isHighlighted = true)

View file

@ -32,8 +32,7 @@ import org.junit.Test
class RetrySendMenuPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val room = FakeMatrixRoom()

View file

@ -29,8 +29,7 @@ import org.junit.Test
class OnBoardingPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -35,8 +35,7 @@ import org.junit.Test
class CreatePollPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private var navUpInvocationsCount = 0

View file

@ -27,8 +27,7 @@ import org.junit.Test
class AboutPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -30,8 +30,7 @@ import org.junit.Test
class AnalyticsSettingsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -35,8 +35,7 @@ import org.junit.Test
class DeveloperSettingsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -30,8 +30,7 @@ import org.junit.Test
class ConfigureTracingPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test
fun `present - initial state`() = runTest {

View file

@ -37,8 +37,7 @@ import org.junit.Test
class PreferencesRootPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -36,8 +36,7 @@ const val A_LONG_DESCRIPTION = "I have seen a bug!"
class BugReportPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -31,8 +31,7 @@ import org.junit.Test
class CrashDetectionPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -38,8 +38,7 @@ import org.junit.Test
class RageshakeDetectionPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
companion object {

View file

@ -31,8 +31,7 @@ import org.junit.Test
class RageshakePreferencesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -57,8 +57,7 @@ import kotlin.time.Duration.Companion.milliseconds
@ExperimentalCoroutinesApi
class RoomDetailsPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private fun aRoomDetailsPresenter(
room: MatrixRoom,

View file

@ -48,8 +48,7 @@ import java.io.File
@ExperimentalCoroutinesApi
class RoomDetailsEditPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var fakePickerProvider: FakePickerProvider

View file

@ -46,8 +46,7 @@ import org.junit.Test
internal class RoomInviteMembersPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -43,8 +43,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -38,8 +38,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberDetailsPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -61,8 +61,7 @@ import org.junit.Test
class RoomListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -35,8 +35,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class VerifySelfSessionPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -35,8 +35,7 @@ const val A_PERMISSION = "A_PERMISSION"
class DefaultPermissionsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -27,8 +27,7 @@ import org.junit.Test
class NoopPermissionsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View file

@ -32,17 +32,22 @@ import kotlin.time.Duration.Companion.seconds
* Applying this test rule ensures that the slow initialisation is not done
* inside runTest which has a short default timeout.
*/
class WarmUpRule: TestRule {
override fun apply(base: Statement, description: Description): Statement = object: Statement() {
override fun evaluate() {
runTest(timeout = 60.seconds) {
moleculeFlow(RecompositionMode.Immediate) {
// Do nothing
}.test {
awaitItem() // Await a Unit composition
}
}
base.evaluate()
class WarmUpRule : TestRule {
companion object {
init {
warmUpMolecule()
}
}
override fun apply(base: Statement, description: Description): Statement = base
}
private fun warmUpMolecule() {
runTest(timeout = 60.seconds) {
moleculeFlow(RecompositionMode.Immediate) {
// Do nothing
}.test {
awaitItem() // Await a Unit composition
}
}
}