-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[6.2] Add some basic tests for Observations with nearly full coverage #82273
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
base: release/6.2
Are you sure you want to change the base?
[6.2] Add some basic tests for Observations with nearly full coverage #82273
Conversation
|
@swift-ci please smoke test |
|
@swift-ci please test |
|
@swift-ci test macOS |
|
@swift-ci please test |
| } | ||
|
|
||
| @Observable | ||
| final class AsyncTestModel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this type doesn't appear to be used – is that expected?
|
|
||
| suite.test("Basic element emission") { | ||
| let model = TestModel() | ||
| var emissionCount = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this variable appears unused
| Task { | ||
| await Task.yield() | ||
| model.name = "updated" | ||
| model.value = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since there's no synchronization, couldn't this result in 'tearing' given the ordering:
- set
model.name - resume L92
- invoke closure
- set
model.value
could this cause test flakes? or is @MainActor being inherited in some way here (if so, perhaps an isolation assertion would be worthwhile)?
| var emissionCount = 0 | ||
|
|
||
| let observations = Observations<Int, Never> { | ||
| model.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tangential question: how is this building since the TestModel type isn't Sendable?
| expectEqual(result1.count, 3) | ||
| expectEqual(result2.count, 3) | ||
| expectEqual(result1[0], 0) // Initial value | ||
| expectEqual(result2[0], 0) // Initial value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this should this compare to [0, 100, 200] if the order is an expected invariant
| expectEqual(result2[0], 0) // Initial value | ||
| } | ||
|
|
||
| suite.test("Task cancellation behavior") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you by chance thought about this possible issue with cancellation?
|
@swift-ci please test macOS |
This is a cherry pick of the mainline #82272