Skip to content

Commit

Permalink
Instrumentation test coroutines (#7207)
Browse files Browse the repository at this point in the history
Converting SDK instrumentation tests from CountdownLatch to suspending functions
  • Loading branch information
ouchadam authored Sep 27, 2022
1 parent a422361 commit fad0206
Show file tree
Hide file tree
Showing 29 changed files with 1,485 additions and 2,036 deletions.
1 change: 1 addition & 0 deletions changelog.d/7207.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ports SDK instrumentation tests to use suspending functions instead of countdown latches
2 changes: 2 additions & 0 deletions matrix-sdk-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ dependencies {
androidTestImplementation libs.mockk.mockkAndroid
androidTestImplementation libs.androidx.coreTesting
androidTestImplementation libs.jetbrains.coroutinesAndroid
androidTestImplementation libs.jetbrains.coroutinesTest

// Plant Timber tree for test
androidTestImplementation libs.tests.timberJunitRule

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class ChangePasswordTest : InstrumentedTest {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = false))

// Change password
commonTestHelper.runBlockingTest {
session.accountService().changePassword(TestConstants.PASSWORD, NEW_PASSWORD)
}
session.accountService().changePassword(TestConstants.PASSWORD, NEW_PASSWORD)

// Try to login with the previous password, it will fail
val throwable = commonTestHelper.logAccountWithError(session.myUserId, TestConstants.PASSWORD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,20 @@ class DeactivateAccountTest : InstrumentedTest {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))

// Deactivate the account
commonTestHelper.runBlockingTest {
session.accountService().deactivateAccount(
eraseAllData = false,
userInteractiveAuthInterceptor = object : UserInteractiveAuthInterceptor {
override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation<UIABaseAuth>) {
promise.resume(
UserPasswordAuth(
user = session.myUserId,
password = TestConstants.PASSWORD,
session = flowResponse.session
)
)
}
session.accountService().deactivateAccount(
eraseAllData = false,
userInteractiveAuthInterceptor = object : UserInteractiveAuthInterceptor {
override fun performStage(flowResponse: RegistrationFlowResponse, errCode: String?, promise: Continuation<UIABaseAuth>) {
promise.resume(
UserPasswordAuth(
user = session.myUserId,
password = TestConstants.PASSWORD,
session = flowResponse.session
)
)
}
)
}
}
)

// Try to login on the previous account, it will fail (M_USER_DEACTIVATED)
val throwable = commonTestHelper.logAccountWithError(session.myUserId, TestConstants.PASSWORD)
Expand All @@ -74,23 +72,19 @@ class DeactivateAccountTest : InstrumentedTest {
// Try to create an account with the deactivate account user id, it will fail (M_USER_IN_USE)
val hs = commonTestHelper.createHomeServerConfig()

commonTestHelper.runBlockingTest {
commonTestHelper.matrix.authenticationService.getLoginFlow(hs)
}
commonTestHelper.matrix.authenticationService.getLoginFlow(hs)

var accountCreationError: Throwable? = null
commonTestHelper.runBlockingTest {
try {
commonTestHelper.matrix.authenticationService
.getRegistrationWizard()
.createAccount(
session.myUserId.substringAfter("@").substringBefore(":"),
TestConstants.PASSWORD,
null
)
} catch (failure: Throwable) {
accountCreationError = failure
}
try {
commonTestHelper.matrix.authenticationService
.getRegistrationWizard()
.createAccount(
session.myUserId.substringAfter("@").substringBefore(":"),
TestConstants.PASSWORD,
null
)
} catch (failure: Throwable) {
accountCreationError = failure
}

// Test the error
Expand Down
Loading

0 comments on commit fad0206

Please sign in to comment.