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

iOS: WaitFor Method using withTimeout is setting test into constant Loop and it will not go on #4449

Open
2 tasks done
alexandravychytill opened this issue Apr 12, 2024 · 10 comments

Comments

@alexandravychytill
Copy link

alexandravychytill commented Apr 12, 2024

What happened?

await waitFor(element(by.id(elementId))) .toBeVisible() .withTimeout(timeout); sets test into constant loop, for android current implementation working all fine.

Message:

The app is busy with the following tasks:
• There are 2 work items pending on the dispatch queue: "Main Queue (<OS_dispatch_queue_main: com.apple.main-thread>)".
• Run loop "Main Run Loop" is awake.

What was the expected behaviour?

only should go on till as defined amount of seconds

Was it tested on latest Detox?

  • I have tested this issue on the latest Detox release and it still reproduces.

Did your test throw out a timeout?

Help us reproduce this issue!

await waitFor(element(by.id(""))) .toBeVisible() .withTimeout(5000);

In what environment did this happen?

Detox version: 20.20.1
React Native version: 0.72.0
Has Fabric (React Native's new rendering system) enabled: yes
Node version: >=16
Device model: iPhone 15
iOS version: 17.2
macOS version: 14.4
Xcode version: 15.2
Test-runner (select one): jest

Detox logs

Detox logs
The app is busy with the following tasks:
• There are 2 work items pending on the dispatch queue: "Main Queue (<OS_dispatch_queue_main: com.apple.main-thread>)".

After a while: 

The app has not responded to the network requests below:
  (id = 6) invoke: {"type":"expectation","predicate":{"type":"id","value":"home-tab","isRegex":false},"expectation":"toBeVisible","timeout":2000}

Unresponded network requests might result in timeout errors in Detox tests.

• Run loop "Main Run Loop" is awake.

Device logs

Device logs
paste your device.log here!

More data, please!

No response

@asafkorem
Copy link
Contributor

@alexandravychytill I suspect that the app's main thread is blocked even before the wait-for assertion. To verify, you can try the assertion without the wait-for and timeout parts and see if you get the same result.

The issue with the main thread can happen for various reasons, and you might find our troubleshooting documentation helpful for this

If you continue to face difficulties with this issue, consider using the following workaround flag for DetoxSync to bypass the main run-loop sync issue:

await device.launchApp({
  ...
  launchArgs: {
    DTXDisableMainRunLoopSync: true,
  }
});

@asafkorem asafkorem self-assigned this Apr 13, 2024
@alexandravychytill
Copy link
Author

So I tried the launchArgs, but still when using the setTimout function it is looping with this message:

The app is busy with the following tasks:
• There are 2 work items pending on the dispatch queue: "Main Queue (<OS_dispatch_queue_main: com.apple.main-thread>)".
• Run loop "Main Run Loop" is awake.

The app on it's own is loading a few seconds due to internet connection after login, thats why I use the setTimout function, so all AC are visible after internet connection is established. On Android setTimout is working fine as said, but on iOS still there is always a loop when using it.

@mroswald
Copy link

@asafkorem Is there anything else to do other than adding the launchArgs? I updated the detox version to the latest in my package.json, but I have the feeling this flag doesn't change anything.

await device.launchApp({
  ...
  launchArgs: {
    DTXDisableMainRunLoopSync: true,
  }
});

@alexandravychytill
Copy link
Author

@asafkorem Is it possible, that .withTimeout(timeout) is just not working currently for iOS?

@alexandravychytill
Copy link
Author

alexandravychytill commented Apr 22, 2024

Feel like my issue is related to #4282, was there ever a good solution found @asafkorem?

Additional log:

The app has not responded to the network requests below:
  (id = 11) invoke: {"type":"expectation","predicate":{"type":"id","value":"home-tab","isRegex":false},"expectation":"toBeVisible","timeout":5000}

That might be the reason why the test "Login display Home view" has timed out.

@asafkorem
Copy link
Contributor

@alexandravychytill are you sure the app didn't crash or something?
Can you please provide the full logs? preferably with --loglevel trace

@asafkorem
Copy link
Contributor

@mroswald are you sharing the same app and issue with @alexandravychytill? if not, can you please open a different issue and provide the error message + logs you're getting? If that's not the same case it might be a different issue..

@mroswald
Copy link

No, just wanted to know more about this flag as it's not documented anywhere.

@asafkorem
Copy link
Contributor

asafkorem commented Apr 24, 2024

@mroswald This is not-official or documented on purpose, I'm testing this new behaviour (experimental).
It bypasses the main run loop check in Detox's synchronization mechanism on iOS when there's no other busy resource we can identify (like animations, network requests, timers etc.). In such scenarios, it becomes difficult to understand why the app seems busy and why Detox appears to be "stuck," even though something is pending in the main run-loop which is a real issue. Usually, there's no good reason to delay Detox from continuing the execution..

@alexandravychytill
Copy link
Author

alexandravychytill commented Apr 24, 2024

@asafkorem so after some investigation I found out, that the webview is causing my synchronization issue. As in the issue #4438 described, when sharedCookiesEnabled is set to true, the synchronization problem on iOS is happening. My current fix is to disable sharedCookiesEnabled when testing with detox. But I would appreciate if you could investigate further and find a fix, so detox tests on iOS do not crash when sharedCookiesEnabled is true 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants