You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a lot of unit tests that we've been running locally without any problems in the past. However, after migrating these tests to a GitHub Action, we noticed that some of the tested StateFlows were collapsing multiple expected states into one, which resulted in assertion errors. It took me a while to reproduce this locally as a minimal working example. It seems that the sheer number of tests is causing this behavior:
Because many of our tests are similar to this example, we wrote a more sophisticated awaitItem() function that can skip states that are not of interest (e.g., skipping the loading state when checking for the success state):
/** * Skips items of other types until the wanted item type is received and its predicate passes.*/suspendinlinefun <reifiedT> ReceiveTurbine<inT>.awaitItemType(
predicate: (T) ->Boolean = { true }
): T {
var item = awaitItem()
var predicatePassed = (item as?T)?.let(predicate) ?:falsewhile (item !isT|| predicatePassed.not()) {
item = awaitItem()
predicatePassed = (item as?T)?.let(predicate) ?:false
}
return item
}
Would it be possible to add a similar function to Turbine? Or did we miss something in our test setup? Any help would be appreciated! 😊
The text was updated successfully, but these errors were encountered:
My only concern with a function like that is that it can hide legitimate test issues: by skipping items that are not of interest, we also prevent failures that may occur when something weird is emitted that shouldn't have been.
In addition to that, I would advise auditing the code in question for usage of Dispatchers.Default or other multithreaded dispatchers in test. Multithreading will always introduce the potential for flaky tests, which may consistently pass locally and then fail on CI. This happens because the OS thread scheduler is not controlled by the test; depending on how it chooses to run those threads, different results may occur. Without multithreading, otoh, the execution path should be completely unambiguous, so no flakiness (for that reason, at least) can occur.
First, thanks for this nice library :)
We have a lot of unit tests that we've been running locally without any problems in the past. However, after migrating these tests to a GitHub Action, we noticed that some of the tested
StateFlows
were collapsing multiple expected states into one, which resulted in assertion errors. It took me a while to reproduce this locally as a minimal working example. It seems that the sheer number of tests is causing this behavior:Because many of our tests are similar to this example, we wrote a more sophisticated
awaitItem()
function that can skip states that are not of interest (e.g., skipping the loading state when checking for the success state):Would it be possible to add a similar function to Turbine? Or did we miss something in our test setup? Any help would be appreciated! 😊
The text was updated successfully, but these errors were encountered: