https://kotlinlang.org logo
#compose
Title
# compose
v

vide

11/21/2023, 8:45 AM
I'm having a super weird bug again with integrated tests,
onClick
is sometimes not called on a node, (seemingly) because the node is not displayed yet. However the test tag still exists. 🧵
log looks like this
Copy code
W  clicking...
 W  interaction: androidx.compose.foundation.interaction.PressInteraction$Press@b0db5ac
 W  interaction: androidx.compose.foundation.interaction.PressInteraction$Release@e1bea7b
    [missing an onClick log here]
 W  ...clicked
and the code just looks like this
Copy code
.clickable(
    indication = null,
    interactionSource = interactionSource,
    onClick = {
        logger.warn("onClick")
        // other stuff
    }
)
what could be the cause of this? if I add an aritificial delay of say 500ms before clicking, it works normally
t

theapache64

11/21/2023, 8:58 AM
whats ur compose version ?
v

vide

11/21/2023, 9:02 AM
1.6.0-alpha07
Another flaky test I have doesn't seem to sometimes even get an interaction event.
t

theapache64

11/21/2023, 9:30 AM
tried with 1.6.0-beta01 ? i usually bump to latest version as a first step of debugging 😄
v

vide

11/21/2023, 9:32 AM
no, there's another issue preventing upgrading at this point 😐
I guess I could still try
t

theapache64

11/21/2023, 9:32 AM
there’s another issue preventing upgrading at this point
ooops.. which one ?
And it's quite hard to be sure of when it's working, as said this is flaky and not failing every time. It fails about 10% of test runs
t

theapache64

11/21/2023, 9:34 AM
ohh 😮
v

vide

11/21/2023, 9:47 AM
hm, I think I know why it's happening
the component doesn't seem to be displayed yet when it's trying to click it
it's weird because I even try calling
composeTestRule.waitForIdle()
before trying to click, I would assume it would only continue after everything in the current recomposition is displayed etc
t

theapache64

11/21/2023, 9:49 AM
aah.. wait till full-draw should work then
v

vide

11/21/2023, 9:49 AM
so when it fails to click,
assertIsDisplayed()
also fails the assert
t

theapache64

11/21/2023, 9:50 AM
hmm.. wait until displayed is needed here i guess
.
Copy code
device.wait(
    Until.hasObject(findBy()),
    timeout.inWholeMilliseconds
)
should do the magic
v

vide

11/21/2023, 10:28 AM
uhh, what test apis are these?
I wonder what the fundamental reason here is that 1. The component isn't displayed yet even though the test tag is in the tree 2. The click event doesn't go through when it's not displayed. Does the test runner try to actually "click" some coordinates on the screen instead of somehow delivering the event directly?
Copy code
isPlaced=true,
isAttached=true,
boundsInWindow=Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)
🤔
z

Zach Klippenstein (he/him) [MOD]

11/21/2023, 1:08 PM
There are a few places where zero-size nodes are treated as non-existent, since they are effectively hidden from the users perspective. Seems like you might be hitting that?
v

vide

11/21/2023, 1:16 PM
Do you have any idea why any elements would be zero-sized? I had the impression the test framework waits for the UI to be idle? I'm seeing this on nodes which definitely have a non-zero size defined
Reviewing some other flaky tests, it also seems like
waitUntilNodeCount
also sometimes returns when the node isn't even attached yet 😅
z

Zach Klippenstein (he/him) [MOD]

11/21/2023, 5:15 PM
Sounds like a bug on our end