Skip to content

Kmp-ify testutils-ktx#518

Closed
veyndan wants to merge 2 commits intoandroidx:androidx-mainfrom
veyndan:270612487/kmpify-testutils-ktx
Closed

Kmp-ify testutils-ktx#518
veyndan wants to merge 2 commits intoandroidx:androidx-mainfrom
veyndan:270612487/kmpify-testutils-ktx

Conversation

@veyndan
Copy link
Copy Markdown
Contributor

@veyndan veyndan commented Apr 14, 2023

Upstreaming Multiplatform Paging's kmp-ified testutils-ktx. See #505 (comment) for more context.

Test: ./gradlew test connectedCheck
Bug: 270612487

@veyndan veyndan force-pushed the 270612487/kmpify-testutils-ktx branch 4 times, most recently from 45c4fa3 to 79040b3 Compare April 14, 2023 17:22
Comment thread gradle/libs.versions.toml Outdated
sqldelightAndroid = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }
sqldelightCoroutinesExt = { module = "com.squareup.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
sqliteJdbc = { module = "org.xerial:sqlite-jdbc", version = "3.36.0" }
statelyIsoCollections = { module = "co.touchlab:stately-iso-collections", version = "1.2.0" }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From the comments here, it seems like this library is completely deprecated and seems to say that the ArrayDeque that is now part of the Kotlin Standard Library should be enough. Do all the tests still pass if we swap to the stdlib version?

Copy link
Copy Markdown
Contributor Author

@veyndan veyndan Apr 14, 2023

Choose a reason for hiding this comment

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

[…] it seems like this library is completely deprecated […]

The library isn't deprecated, but the module is. Unfortunately, the proposed replacement (stately-concurrent-collections) for this module isn't stable yet.

[…] and seems to say that the ArrayDeque that is now part of the Kotlin Standard Library should be enough.

A KMP version of java.util.ArrayDeque was added in Kotlin 1.3.70. Like java.util.ArrayDeque, kotlin.collections.ArrayDeque isn't thread-safe.

Do all the tests still pass if we swap to the stdlib version?

From the previous point, ArrayQueue isn't thread-safe. Swapping out IsoArrayDeque with ArrayDeque could make all the tests pass, but those tests would presumably be a bit flaky.

@claraf3 claraf3 self-requested a review April 19, 2023 17:25
@claraf3 claraf3 requested a review from ianhanniballake April 24, 2023 17:49
@claraf3
Copy link
Copy Markdown
Member

claraf3 commented May 5, 2023

Hi @veyndan thank you for your patience. After we merged your other PRs removing most usages of TestDispatcher, the remaining tests still using it appears to be single threaded access to the queue. I think its safe to at this point to switch to ArrayDequeue. I think this might be a better route for now so we can prevent the negatives of introducing a deprecated 3rd party module.

@veyndan veyndan force-pushed the 270612487/kmpify-testutils-ktx branch 2 times, most recently from daedd4a to c46c51a Compare May 8, 2023 10:18
@veyndan veyndan force-pushed the 270612487/kmpify-testutils-ktx branch from c46c51a to a261291 Compare May 8, 2023 10:18
@veyndan
Copy link
Copy Markdown
Contributor Author

veyndan commented May 8, 2023

@claraf3 Sounds good to me! I've just updated the PR to use ArrayDeque, but I'm getting a CI error. It seems unrelated to my changes though.

@claraf3
Copy link
Copy Markdown
Member

claraf3 commented May 8, 2023

Awesome, thank you Veyndan! Yeah it looks to be our issue. Don't worry about it :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're getting a lint failure on this file:

$SUPPORT/testutils/testutils-ktx/src/jvmMain/kotlin/androidx/testutils/VerifyWithPolling.kt:29: Error: Uses Thread.sleep() [BanThreadSleep from androidx.build]
Thread.sleep(periodMs)
~~~~~

Explanation for issues of type "BanThreadSleep":
Use of Thread.sleep() is not allowed, please use a callback or another way
to make more reliable code. See more details at
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:docs/testability.md#calling-threadsleep-as-a-synchronization-barrier

Do you mind seeing if you can suppress the BanThreadSleep check here? Ideally you should be able to reproduce this with by running :internal-testutils-ktx:lint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried recreating this issue locally, but it always passes. I'm running the following command within the paging directory:

./gradlew :internal-testutils-ktx:lint --rerun-tasks --no-configuration-cache   

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was able to repro the error on my end. I added the suppression and its running through checks. Should be good now, thanks for trying!

@copybara-service copybara-service bot closed this in 71a449b May 9, 2023
@veyndan veyndan deleted the 270612487/kmpify-testutils-ktx branch May 9, 2023 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants