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

Why is VirtualTimeScheduler checking to ensure it's on the main thread? #2609

Open
5 of 17 tasks
danielt1263 opened this issue Jul 10, 2024 · 0 comments · May be fixed by #2610
Open
5 of 17 tasks

Why is VirtualTimeScheduler checking to ensure it's on the main thread? #2609

danielt1263 opened this issue Jul 10, 2024 · 0 comments · May be fixed by #2610

Comments

@danielt1263
Copy link
Collaborator

danielt1263 commented Jul 10, 2024

RxTest's TestScheduler causes a crash when used in Swift Testing:

When running a test inside the Swift Testing system, the TestScheduler uses VirtualTimeScheduler which, at several points, checks to ensure it's running on the main thread. However since Swift Testing runs tests on background threads, the test harness will crash on the assertion.

Expected outcome:

I expected that VirtualTimeScheduler would be thread agnostic. At worst, it would ensure that all its methods were run on the same thread as the start method was run on, but that's about it.

What actually happens:

The VirtualTimeScheduler asserts because it's not being run on the main thread.

Self contained code example that reproduces the issue:

struct ExampleTests {
    @Test func testExample() async throws {
        let scheduler = TestScheduler(initialClock: 0)
        scheduler.start()
    }
}

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

6.7.1

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

  Version 16.0 beta 2 (16A5171r)

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (Version 16.0 beta 2 (16A5171r), 15.4)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@danielt1263 danielt1263 linked a pull request Jul 10, 2024 that will close this issue
@danielt1263 danielt1263 linked a pull request Jul 10, 2024 that will close this issue
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 a pull request may close this issue.

1 participant