@@ -45,40 +45,58 @@ final class ViewStoreTests: XCTestCase {
45
45
}
46
46
47
47
func test_sensitiveState( ) async {
48
- var counts : [ Int ] = [ ]
49
- var sensitiveCounts : [ Int ] = [ ]
48
+ actor Result {
49
+ var counts : [ Int ] = [ ]
50
+ var sensitiveCounts : [ Int ] = [ ]
51
+ func appendCount( _ count: Int ) {
52
+ counts. append ( count)
53
+ }
54
+ func appendSensitiveCount( _ count: Int ) {
55
+ sensitiveCounts. append ( count)
56
+ }
57
+ }
58
+ let result = Result ( )
50
59
51
- Task {
60
+ Task { @ MainActor in
52
61
for await state in sut. states {
53
- counts . append ( state. count)
62
+ await result . appendCount ( state. count)
54
63
}
55
64
}
56
- Task {
65
+ Task { @ MainActor in
57
66
for await sensitiveCount in sut. states. sensitiveCount {
58
- sensitiveCounts . append ( sensitiveCount)
67
+ await result . appendSensitiveCount ( sensitiveCount)
59
68
}
60
69
}
61
70
62
71
sut. send ( . setSensitiveCount( 10 ) )
63
72
sut. send ( . setSensitiveCount( 10 ) )
64
73
sut. send ( . setSensitiveCount( 10 ) )
65
74
66
- await expect { counts == [ 0 , 0 , 0 , 0 ] }
67
- await expect { sensitiveCounts == [ 0 , 10 , 10 , 10 ] }
75
+ await sendableExpect { await result . counts == [ 0 , 0 , 0 , 0 ] }
76
+ await sendableExpect { await result . sensitiveCounts == [ 0 , 10 , 10 , 10 ] }
68
77
}
69
78
70
79
func test_insensitiveState( ) async {
71
- var counts : [ Int ] = [ ]
72
- var insensitiveCounts : [ Int ] = [ ]
80
+ actor Result {
81
+ var counts : [ Int ] = [ ]
82
+ var insensitiveCounts : [ Int ] = [ ]
83
+ func appendCount( _ count: Int ) {
84
+ counts. append ( count)
85
+ }
86
+ func appendInsensitiveCount( _ count: Int ) {
87
+ insensitiveCounts. append ( count)
88
+ }
89
+ }
90
+ let result = Result ( )
73
91
74
- Task {
92
+ Task { @ MainActor in
75
93
for await state in sut. states {
76
- counts . append ( state. count)
94
+ await result . appendCount ( state. count)
77
95
}
78
96
}
79
- Task {
97
+ Task { @ MainActor in
80
98
for await insensitiveCount in sut. states. insensitiveCount {
81
- insensitiveCounts . append ( insensitiveCount)
99
+ await result . appendInsensitiveCount ( insensitiveCount)
82
100
}
83
101
}
84
102
@@ -87,8 +105,8 @@ final class ViewStoreTests: XCTestCase {
87
105
sut. send ( . setInsensitiveCount( 30 ) )
88
106
89
107
// only initial value
90
- await expect { counts == [ 0 ] }
91
- await expect { insensitiveCounts == [ 0 ] }
108
+ await sendableExpect { await result . counts == [ 0 ] }
109
+ await sendableExpect { await result . insensitiveCounts == [ 0 ] }
92
110
}
93
111
94
112
func test_asyncViewStateSequence( ) async {
@@ -107,7 +125,7 @@ final class ViewStoreTests: XCTestCase {
107
125
let expectation = expectation ( description: #function)
108
126
109
127
let result = Result ( expectation, expectedCount: 15 )
110
- Task {
128
+ Task { @ MainActor in
111
129
await withTaskGroup ( of: Void . self) { group in
112
130
group. addTask { await self . consumeAsyncViewStateSequence1 ( result) }
113
131
group. addTask { await self . consumeAsyncViewStateSequence2 ( result) }
0 commit comments