@@ -265,6 +265,52 @@ class StorageResultTests: StorageIntegrationCommon {
265265 waitForExpectations ( )
266266 }
267267
268+ func testPutFileLimitedChunk( ) throws {
269+ let expectation = self . expectation ( description: #function)
270+ let putFileExpectation = self . expectation ( description: " putFile " )
271+ let ref = storage. reference ( withPath: " ios/public/testPutFilePauseResume " )
272+ let bundle = Bundle ( for: StorageIntegrationCommon . self)
273+ let filePath = try XCTUnwrap ( bundle. path ( forResource: " 1mb " , ofType: " dat " ) ,
274+ " Failed to get filePath " )
275+ let data = try XCTUnwrap ( try Data ( contentsOf: URL ( fileURLWithPath: filePath) ) ,
276+ " Failed to load file " )
277+ let tmpDirURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
278+ let fileURL = tmpDirURL. appendingPathComponent ( " LargePutFile.txt " )
279+ var progressCount = 0
280+
281+ try data. write ( to: fileURL, options: . atomicWrite)
282+
283+ // Limit the upload chunk size
284+ storage. uploadChunkSizeBytes = 256_000
285+
286+ let task = ref. putFile ( from: fileURL) { result in
287+ XCTAssertGreaterThanOrEqual ( progressCount, 4 )
288+ self . assertResultSuccess ( result)
289+ putFileExpectation. fulfill ( )
290+ }
291+
292+ task. observe ( StorageTaskStatus . success) { snapshot in
293+ XCTAssertEqual ( snapshot. description, " <State: Success> " )
294+ expectation. fulfill ( )
295+ }
296+
297+ var uploadedBytes : Int64 = - 1
298+
299+ task. observe ( StorageTaskStatus . progress) { snapshot in
300+ XCTAssertTrue ( snapshot. description. starts ( with: " <State: Progress " ) ||
301+ snapshot. description. starts ( with: " <State: Resume " ) )
302+ guard let progress = snapshot. progress else {
303+ XCTFail ( " Failed to get snapshot.progress " )
304+ return
305+ }
306+ progressCount = progressCount + 1
307+ XCTAssertGreaterThanOrEqual ( progress. completedUnitCount, uploadedBytes)
308+ uploadedBytes = progress. completedUnitCount
309+ }
310+ waitForExpectations ( )
311+ storage. uploadChunkSizeBytes = Int64 . max
312+ }
313+
268314 func testAttemptToUploadDirectoryShouldFail( ) throws {
269315 // This `.numbers` file is actually a directory.
270316 let fileName = " HomeImprovement.numbers "
0 commit comments