File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
FilestackSDK/Internal/Uploaders Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,12 @@ class MultipartUpload: Uploader, DeferredAdd {
6868
6969 uploadQueue. sync {
7070 state = . cancelled
71- operationQueue. cancelAllOperations ( )
71+
72+ if uploadables == nil || uploadables? . count == 0 {
73+ finish ( with: [ ] )
74+ } else {
75+ operationQueue. cancelAllOperations ( )
76+ }
7277 }
7378
7479 return true
Original file line number Diff line number Diff line change @@ -131,6 +131,46 @@ class UploadTests: XCTestCase {
131131 XCTAssertNotNil ( error)
132132 }
133133
134+ func testCancellingStartedUploadWithoutUploadablesShouldCallCompletionHandler( ) {
135+ let expectation = self . expectation ( description: " request should succeed " )
136+ var response : [ JSONResponse ] = [ ]
137+
138+ let uploadOptions = UploadOptions ( preferIntelligentIngestion: true , startImmediately: true )
139+
140+ let uploader = client. upload ( options: uploadOptions) { resp in
141+ response = resp
142+ expectation. fulfill ( )
143+ }
144+
145+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
146+ uploader. cancel ( )
147+ }
148+
149+ waitForExpectations ( timeout: 15 , handler: nil )
150+
151+ XCTAssertEqual ( response, [ ] )
152+ }
153+
154+ func testCancellingNotStartedUploadWithoutUploadablesShouldCallCompletionHandler( ) {
155+ let expectation = self . expectation ( description: " request should succeed " )
156+ var response : [ JSONResponse ] = [ ]
157+
158+ let uploadOptions = UploadOptions ( preferIntelligentIngestion: true , startImmediately: false )
159+
160+ let uploader = client. upload ( options: uploadOptions) { resp in
161+ response = resp
162+ expectation. fulfill ( )
163+ }
164+
165+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
166+ uploader. cancel ( )
167+ }
168+
169+ waitForExpectations ( timeout: 15 , handler: nil )
170+
171+ XCTAssertEqual ( response, [ ] )
172+ }
173+
134174 func testResumableMultiPartUploadWithDownNetworkOnStart( ) {
135175 let uploadMultipartStartStubConditions =
136176 isScheme ( Constants . uploadURL. scheme!) &&
You can’t perform that action at this time.
0 commit comments