Skip to content

Commit d30efd3

Browse files
committed
Test
tweak test tweaks
1 parent fc5cbee commit d30efd3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Tests/ComposableArchitectureTests/CurrentValueRelayTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,34 @@
2525

2626
_ = cancellable
2727
}
28+
29+
func testConcurrentSendAndReceive() async {
30+
nonisolated(unsafe) let subject = CurrentValueRelay(0)
31+
let values = LockIsolated<Set<Int>>([])
32+
let cancellable = subject.sink { (value: Int) in
33+
values.withValue {
34+
_ = $0.insert(value)
35+
}
36+
}
37+
38+
let receives = Task.detached { @Sendable in
39+
for await _ in subject.values {}
40+
}
41+
42+
await withTaskGroup(of: Void.self) { group in
43+
for index in 1...1_000 {
44+
group.addTask { @Sendable in
45+
subject.send(index)
46+
}
47+
}
48+
}
49+
50+
receives.cancel()
51+
_ = await receives.value
52+
53+
XCTAssertEqual(values.value, Set(Array(0...1_000)))
54+
55+
_ = cancellable
56+
}
2857
}
2958
#endif

0 commit comments

Comments
 (0)