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

Instrumentation test coroutines #7207

Merged
merged 56 commits into from
Sep 27, 2022
Merged

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Sep 22, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Updates all of the sdk instrumentation tests to use suspending functions, replacing CountdownLatch usages

Motivation and context

To help improve test stability and time taken to execute

Before: 23m 43s
After: 6m 34s

72% reduction in runtime, saving around 17 minutes~

Screenshots / GIFs

Before After
2022-09-21T15:28:49,352822323+01:00 2022-09-22T13:55:36,281502272+01:00

|

Tests

Run the ./gradlew matrix-sdk-android:connectedAndroidTest, or all the matrix-sdk-android androidTest tests from within Android Studio

Tested devices

  • Physical
  • Emulator
  • OS version(s): 31

@ouchadam ouchadam marked this pull request as ready for review September 22, 2022 13:11
@ouchadam
Copy link
Contributor Author

for reviewers, enabling hide whitespace will provide a much better diff and the PR should be merged as a squash (the commits were used as checkpoints to ensure all tests continued to pass during the refactors)

@ouchadam ouchadam requested review from a team and onurays and removed request for a team September 22, 2022 13:12
@ouchadam ouchadam changed the title [WIP] Instrumentation test coroutines Instrumentation test coroutines Sep 22, 2022
Base automatically changed from feature/adm/configurable-sync-timeout to develop September 22, 2022 14:40
@ouchadam ouchadam force-pushed the feature/adm/coroutine-instrumentation branch from 955ac8d to ad8786d Compare September 22, 2022 14:41
@@ -34,6 +35,7 @@ import java.util.UUID

@RunWith(AndroidJUnit4::class)
@LargeTest
@Ignore // Temporary ignore whilst confirming other tests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm currently investigating re-enabling this and the VoiceRecorderLTests tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CantVerifyTest is fixed by #7210
VoiceRecorderLTests is fixed by #7226

@ouchadam ouchadam force-pushed the feature/adm/coroutine-instrumentation branch from ad8786d to 1db0ef4 Compare September 23, 2022 10:14
@ouchadam ouchadam changed the base branch from develop to feature/bma/ignore_flaky_test September 23, 2022 10:14
@bmarty bmarty force-pushed the feature/bma/ignore_flaky_test branch from 9c42b87 to 97b3b23 Compare September 23, 2022 12:09
Base automatically changed from feature/bma/ignore_flaky_test to develop September 23, 2022 13:10
@ouchadam ouchadam force-pushed the feature/adm/coroutine-instrumentation branch from 1db0ef4 to 3f83afb Compare September 23, 2022 13:26
@ouchadam ouchadam added the PR-Large PR with more than 500 updated lines label Sep 23, 2022
@ouchadam ouchadam force-pushed the feature/adm/coroutine-instrumentation branch from 3f83afb to c595475 Compare September 26, 2022 13:08
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -43,9 +43,7 @@ class ChangePasswordTest : InstrumentedTest {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = false))

// Change password
commonTestHelper.runBlockingTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the runCryptoTest & runSessionTest are now suspending which means runBlockingTest is the equivalent of running in the original scope

testHelper.cleanUpOpenedSessions()
return runTest(dispatchTimeoutMs = TestConstants.timeOutMillis) {
try {
withContext(Dispatchers.Default) {
Copy link
Contributor Author

@ouchadam ouchadam Sep 26, 2022

Choose a reason for hiding this comment

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

we use the Default context to allow Timeouts to work correctly, the original runTest dispatcher uses a test scheduler which requires the scheduler timings to be manually incremented, otherwise timing based suspensions like delay/timeout complete instantly (which we don't want!)

* limitations under the License.
*/

package org.matrix.android.sdk.common
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reusable test functions, more functions could lifted from the testHelper now that the helpers are mostly stateless~

@@ -173,25 +141,18 @@ class UnwedgingTest : InstrumentedTest {
bobSession.cryptoService().getMyDevice().identityKey()!!
)
olmDevice.clearOlmSessionCache()
Thread.sleep(6_000)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should avoid any thread sleeps and instead rely on dynamic updates from retryPeriodic, waitFor, suspendCancellableCoroutine


messagesReceivedByBob.size shouldBe 1
messagesReceivedByBob.size shouldBeEqualTo 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

shouldBe uses reference equality === whereas shouldBeEqualTo uses value equality ==

@@ -135,7 +126,7 @@ class E2EShareKeysConfigTest : InstrumentedTest {
}

@Test
fun ifSharingDisabledOnAliceSideBobShouldNotShareAliceHistoty() = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
fun ifSharingDisabledOnAliceSideBobShouldNotShareAliceHistory() = runCryptoTest(context()) { cryptoTestHelper, commonTestHelper ->
Copy link
Member

Choose a reason for hiding this comment

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

🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thought I'd fix it whilst I was in the area 😄

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Awesome work, LGTM. Some documentation above fun in https://github.com/vector-im/element-android/blob/3e46263bef7d480b441477ecf98589d79610e873/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestExtensions.kt could help, but I can add it later, to not block this PR from being merged.

@ouchadam
Copy link
Contributor Author

@bmarty agreed! we could also lift some of the TestHelper functions out as extensions/file level functions as well

@ouchadam ouchadam merged commit fad0206 into develop Sep 27, 2022
@ouchadam ouchadam deleted the feature/adm/coroutine-instrumentation branch September 27, 2022 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Large PR with more than 500 updated lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants