Skip to content

Commit

Permalink
Storage Integration Test flakiness (#12235)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Jan 3, 2024
1 parent 0fe8385 commit 1104c72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions FirebaseStorage/Tests/Integration/StorageAsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class StorageAsyncAwait: StorageIntegrationCommon {
let ref = storage.reference(withPath: "ios/public/" + fileName)
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
try data.write(to: fileURL, options: .atomicWrite)
let metadata = try await ref.putFileAsync(from: fileURL)
XCTAssertEqual(fileName, metadata.name)
Expand Down Expand Up @@ -182,7 +182,7 @@ class StorageAsyncAwait: StorageIntegrationCommon {
let ref = storage.reference(withPath: "ios/public/testSimplePutFile")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
try data.write(to: fileURL, options: .atomicWrite)
var uploadedBytes: Int64 = -1
let successMetadata = try await ref.putFileAsync(from: fileURL) { progress in
Expand Down Expand Up @@ -251,21 +251,21 @@ class StorageAsyncAwait: StorageIntegrationCommon {
}

func testAsyncWrite() async throws {
let ref = storage.reference(withPath: "ios/public/helloworld")
let ref = storage.reference(withPath: "ios/public/helloworld" + #function)
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")

_ = try await ref.putDataAsync(data)
let url = try await ref.writeAsync(toFile: fileURL)
XCTAssertEqual(url.lastPathComponent, "hello.txt")
XCTAssertEqual(url.lastPathComponent, #function + "hello.txt")
}

func testSimpleGetFile() throws {
let expectation = self.expectation(description: #function)
let ref = storage.reference(withPath: "ios/public/helloworld")
let ref = storage.reference(withPath: "ios/public/helloworld" + #function)
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")

Task {
Expand Down
10 changes: 5 additions & 5 deletions FirebaseStorage/Tests/Integration/StorageIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ class StorageResultTests: StorageIntegrationCommon {

func testSimpleGetFile() throws {
let expectation = self.expectation(description: #function)
let ref = storage.reference(withPath: "ios/public/helloworld")
let ref = storage.reference(withPath: "ios/public/helloworld" + #function)
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")

ref.putData(data) { result in
Expand Down Expand Up @@ -577,16 +577,15 @@ class StorageResultTests: StorageIntegrationCommon {

func testCancelErrorCode() throws {
let expectation = self.expectation(description: #function)
let ref = storage.reference(withPath: "ios/public/helloworld")
let ref = storage.reference(withPath: "ios/public/helloworld" + #function)
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory())
let fileURL = tmpDirURL.appendingPathComponent("hello.txt")
let fileURL = tmpDirURL.appendingPathComponent(#function + "hello.txt")
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")

ref.putData(data) { result in
switch result {
case .success:
let task = ref.write(toFile: fileURL)
task.cancel()

task.observe(StorageTaskStatus.success) { snapshot in
XCTFail("Error processing success snapshot")
Expand All @@ -603,6 +602,7 @@ class StorageResultTests: StorageIntegrationCommon {
}
expectation.fulfill()
}
task.cancel()
case let .failure(error):
XCTFail("Unexpected error \(error) from putData")
expectation.fulfill()
Expand Down

0 comments on commit 1104c72

Please sign in to comment.