@@ -175,6 +175,47 @@ class NetworkInstrumentationFeatureTests: XCTestCase {
175
175
_ = server. waitAndReturnRequests ( count: 1 )
176
176
}
177
177
178
+ @available ( iOS 13 . 0 , tvOS 13 . 0 , * )
179
+ func testGivenURLSessionWithCustomDelegate_whenUsingCombineDataFromURL_itNotifiesInterceptor( ) async throws {
180
+ /// Testing only 16.0 or above because 15.0 has ThreadSanitizer issues with async APIs
181
+ guard #available( iOS 16 , tvOS 16 , * ) else {
182
+ return
183
+ }
184
+
185
+ let notifyInterceptionDidStart = expectation ( description: " Notify interception did start " )
186
+ let notifyInterceptionDidComplete = expectation ( description: " Notify intercepion did complete " )
187
+ let server = ServerMock (
188
+ delivery: . success( response: . mockResponseWith( statusCode: 200 ) , data: . mock( ofSize: 10 ) ) ,
189
+ skipIsMainThreadCheck: true
190
+ )
191
+
192
+ handler. onInterceptionDidStart = { _ in notifyInterceptionDidStart. fulfill ( ) }
193
+ handler. onInterceptionDidComplete = { _ in notifyInterceptionDidComplete. fulfill ( ) }
194
+
195
+ // Given
196
+ let delegate = MockDelegate ( )
197
+ try URLSessionInstrumentation . enableOrThrow ( with: . init( delegateClass: MockDelegate . self) , in: core)
198
+ let session = server. getInterceptedURLSession ( delegate: delegate)
199
+
200
+ // When
201
+ _ = session. dataTaskPublisher ( for: URL . mockAny ( ) )
202
+ . sink (
203
+ receiveCompletion: { _ in } ,
204
+ receiveValue: { _ in }
205
+ )
206
+ // Then
207
+ await dd_fulfillment (
208
+ for: [
209
+ notifyInterceptionDidStart,
210
+ notifyInterceptionDidComplete
211
+ ] ,
212
+ timeout: 5 ,
213
+ enforceOrder: true
214
+ )
215
+
216
+ _ = server. waitAndReturnRequests ( count: 1 )
217
+ }
218
+
178
219
func testGivenURLSessionWithCustomDelegate_whenUsingCompletionHandlerDataFromURL_itNotifiesInterceptor( ) throws {
179
220
/// Testing only 16.0 or above because 15.0 has ThreadSanitizer issues with async APIs
180
221
guard #available( iOS 16 , tvOS 16 , * ) else {
0 commit comments