Skip to content

Conversation

@phausler
Copy link
Contributor

This is a cherry pick of the mainline #82272

@phausler phausler requested a review from a team as a code owner June 16, 2025 18:36
@phausler phausler requested a review from stephentyrone June 16, 2025 18:36
@phausler
Copy link
Contributor Author

@swift-ci please smoke test

@phausler
Copy link
Contributor Author

@swift-ci please test

@airspeedswift airspeedswift changed the title Add some basic tests for Observations with nearly full coverage [6.2] Add some basic tests for Observations with nearly full coverage Jun 20, 2025
@stephentyrone
Copy link
Contributor

@swift-ci test macOS

@phausler
Copy link
Contributor Author

@swift-ci please test

}

@Observable
final class AsyncTestModel {
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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:

  1. set model.name
  2. resume L92
  3. invoke closure
  4. 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
Copy link
Contributor

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?

Comment on lines +177 to +180
expectEqual(result1.count, 3)
expectEqual(result2.count, 3)
expectEqual(result1[0], 0) // Initial value
expectEqual(result2[0], 0) // Initial value
Copy link
Contributor

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") {
Copy link
Contributor

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?

@phausler
Copy link
Contributor Author

phausler commented Jul 3, 2025

@swift-ci please test macOS

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 this pull request may close these issues.

3 participants