@@ -48,6 +48,7 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
48
48
sessionOrchestrator. createSession ( withDetails: sampleSessionDetail)
49
49
50
50
// verify that a new session is created
51
+ sleep ( 1 )
51
52
XCTAssertNotNil ( sessionOrchestrator. session)
52
53
XCTAssertIdentical ( sampleSessionDetail, sessionOrchestrator. session? . sessionDetails)
53
54
@@ -77,9 +78,9 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
77
78
sessionOrchestrator. terminateSession ( purgeBuffer: true )
78
79
79
80
// verify
81
+ wait ( for: [ mockSession. disconnectCalled] , timeout: 1.0 )
80
82
XCTAssertTrue ( sessionOrchestrator. hasEverTerminated)
81
83
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
82
- XCTAssertTrue ( mockSession. disconnectCalled)
83
84
XCTAssertNil ( sessionOrchestrator. outboundEventBuffer)
84
85
XCTAssertNil ( sessionOrchestrator. session)
85
86
}
@@ -92,32 +93,38 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
92
93
sessionOrchestrator. queueEvent ( AssuranceEvent ( type: " event1 " , payload: [ : ] ) )
93
94
94
95
// verify
96
+ wait ( for: [ mockSession. sendEventCalled] , timeout: 1.0 )
95
97
XCTAssertTrue ( sessionOrchestrator. outboundEventBuffer!. isEmpty)
96
- XCTAssertTrue ( mockSession. sendEventCalled)
97
98
}
98
99
99
100
func test_queueEvent_whenSessionInActive( ) {
100
101
// setup
101
102
sessionOrchestrator. session = nil
102
103
104
+ // Invert the expectation as we need to verify sendEvent is not called
105
+ mockSession. sendEventCalled. isInverted = true
106
+
103
107
// test
104
108
sessionOrchestrator. queueEvent ( AssuranceEvent ( type: " event1 " , payload: [ : ] ) )
105
109
106
110
// verify
107
- XCTAssertFalse ( mockSession. sendEventCalled)
108
- XCTAssertEqual ( 1 , sessionOrchestrator. outboundEventBuffer!. count)
111
+ wait ( for : [ mockSession. sendEventCalled] , timeout : 1.0 )
112
+ XCTAssertEqual ( 1 , sessionOrchestrator. outboundEventBuffer!. count)
109
113
}
110
114
111
115
func test_queueEvent_whenShutDown( ) {
112
116
// setup
113
117
sessionOrchestrator. session = nil
114
118
sessionOrchestrator. outboundEventBuffer = nil
115
119
120
+ // Invert the expectation as we need to verify sendEvent is not called
121
+ mockSession. sendEventCalled. isInverted = true
122
+
116
123
// test
117
124
sessionOrchestrator. queueEvent ( AssuranceEvent ( type: " event1 " , payload: [ : ] ) )
118
125
119
126
// verify
120
- XCTAssertFalse ( mockSession. sendEventCalled)
127
+ wait ( for : [ mockSession. sendEventCalled] , timeout : 1.0 )
121
128
XCTAssertNil ( sessionOrchestrator. outboundEventBuffer)
122
129
}
123
130
@@ -132,7 +139,7 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
132
139
sessionOrchestrator. pinScreenConnectClicked ( " 3325 " )
133
140
134
141
// verify
135
- XCTAssertTrue ( mockSession. startSessionCalled)
142
+ wait ( for : [ mockSession. startSessionCalled] , timeout : 1.0 )
136
143
}
137
144
138
145
@@ -151,13 +158,16 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
151
158
sessionOrchestrator. authorizingPresentation = mockAuthorizingPresentation
152
159
mockStateManager. orgIDReturnValue = " mockOrgId "
153
160
sessionOrchestrator. session = mockSession
161
+
162
+ // Invert the expectation as we need to verify startSession is not called
163
+ mockSession. startSessionCalled. isInverted = true
154
164
155
165
// test
156
166
sessionOrchestrator. pinScreenConnectClicked ( " " )
157
167
158
168
// verify that the UI is indicated for the error and session is cleared
159
- XCTAssertFalse ( mockSession. startSessionCalled)
160
- XCTAssertTrue ( mockSession. disconnectCalled)
169
+ wait ( for : [ mockSession. startSessionCalled] , timeout : 1.0 )
170
+ wait ( for : [ mockSession. disconnectCalled] , timeout : 1.0 )
161
171
XCTAssertTrue ( mockAuthorizingPresentation. sessionConnectionErrorCalled)
162
172
XCTAssertEqual ( . noPincode , mockAuthorizingPresentation. sessionConnectionErrorValue)
163
173
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
@@ -170,12 +180,15 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
170
180
mockStateManager. orgIDReturnValue = nil
171
181
sessionOrchestrator. session = mockSession
172
182
183
+ // Invert the expectation as we need to verify startSession is not called
184
+ mockSession. startSessionCalled. isInverted = true
185
+
173
186
// test
174
187
sessionOrchestrator. pinScreenConnectClicked ( " 4442 " )
175
188
176
189
// verify that the UI is indicated for the error and session is cleared
177
- XCTAssertFalse ( mockSession. startSessionCalled)
178
- XCTAssertTrue ( mockSession. disconnectCalled)
190
+ wait ( for : [ mockSession. startSessionCalled] , timeout : 1.0 )
191
+ wait ( for : [ mockSession. disconnectCalled] , timeout : 1.0 )
179
192
XCTAssertTrue ( mockAuthorizingPresentation. sessionConnectionErrorCalled)
180
193
XCTAssertEqual ( . noOrgId , mockAuthorizingPresentation. sessionConnectionErrorValue)
181
194
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
@@ -188,9 +201,9 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
188
201
sessionOrchestrator. pinScreenCancelClicked ( )
189
202
190
203
// verify that the session is terminated and cleared
204
+ wait ( for: [ mockSession. disconnectCalled] , timeout: 1.0 )
191
205
XCTAssertTrue ( sessionOrchestrator. hasEverTerminated)
192
206
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
193
- XCTAssertTrue ( mockSession. disconnectCalled)
194
207
XCTAssertNil ( sessionOrchestrator. outboundEventBuffer)
195
208
XCTAssertNil ( sessionOrchestrator. session)
196
209
}
@@ -202,9 +215,9 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
202
215
sessionOrchestrator. disconnectClicked ( )
203
216
204
217
// verify that the session is terminated and cleared
218
+ wait ( for: [ mockSession. disconnectCalled] , timeout: 1.0 )
205
219
XCTAssertTrue ( sessionOrchestrator. hasEverTerminated)
206
220
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
207
- XCTAssertTrue ( mockSession. disconnectCalled)
208
221
XCTAssertNil ( sessionOrchestrator. outboundEventBuffer)
209
222
XCTAssertNil ( sessionOrchestrator. session)
210
223
}
@@ -232,25 +245,25 @@ class AssuranceSessionOrchestratorTests: XCTestCase {
232
245
233
246
XCTAssertTrue ( mockAuthorizingPresentation. sessionConnectingCalled)
234
247
235
- XCTAssertTrue ( mockStateManager. shareAssuranceStateCalled )
248
+ wait ( for : [ mockStateManager. shareAssuranceStateExpectation ] , timeout : 1.0 )
236
249
XCTAssertEqual ( sampleSessionID, mockStateManager. shareAssuranceStateSessionID)
250
+ sleep ( 1 )
237
251
XCTAssertNotNil ( sessionOrchestrator. session)
238
252
XCTAssertNil ( sessionOrchestrator. outboundEventBuffer)
239
253
}
240
254
241
- // This is testing the retry scenario when a session has been created, but the socket connection failed
255
+ // This is testing the retry scenario when a session has been created, but the socket connection failed
242
256
func test_createQuickConnectSession_withExistingSession( ) {
243
257
let mockAuthorizingPresentation = MockAuthorizingPresentation ( authorizingView: MockSessionAuthorizingUI ( withPresentationDelegate: sessionOrchestrator) )
244
258
sessionOrchestrator. authorizingPresentation = mockAuthorizingPresentation
245
- let sampleSessionID = " sampleSessionID "
246
- let sampleSessionDetails = AssuranceSessionDetails ( sessionId: sampleSessionID, clientId: " sampleClientID " )
247
259
queueTwoOutboundEvents ( )
248
- let session = AssuranceSession ( sessionDetails: sampleSessionDetails, stateManager: mockStateManager, sessionOrchestrator: sessionOrchestrator, outboundEvents: sessionOrchestrator. outboundEventBuffer)
249
- sessionOrchestrator. session = session
250
- sessionOrchestrator. createQuickConnectSession ( with: sampleSessionDetails)
260
+ sessionOrchestrator. session = mockSession
261
+ sessionOrchestrator. createQuickConnectSession ( with: mockSession. sessionDetails)
251
262
263
+ wait ( for: [ mockSession. disconnectCalled] , timeout: 1.0 )
252
264
XCTAssertTrue ( mockStateManager. clearAssuranceStateCalled)
253
- XCTAssertNotNil ( session. outboundQueue)
265
+ XCTAssertNotNil ( mockSession. outboundQueue)
266
+ sleep ( 1 )
254
267
XCTAssertNotNil ( sessionOrchestrator. session)
255
268
}
256
269
0 commit comments