Skip to content

Commit

Permalink
tests: Update expectation APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Demaria <[email protected]>
  • Loading branch information
fabriziodemaria committed Jan 11, 2024
1 parent 0d40dda commit 73ae9ce
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
await applier.apply(flagName: "flag2", resolveToken: "token1")
await applier.apply(flagName: "flag3", resolveToken: "token1")

await waitForExpectations(timeout: 1.0)
await fulfillment(of: [networkExpectation], timeout: 1.0)

// Then cache data is not stored on to the disk
// But stored in the local cache as sent
Expand Down Expand Up @@ -149,8 +149,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
metadata: metadata
)

await waitForExpectations(timeout: 5.0)

await fulfillment(of: [expectation, storageExpectation], timeout: 1.0)
// Then http client sends 5 apply flag batch request, containing 20 records each
let request = try XCTUnwrap(httpClient.data?.first as? ApplyFlagsRequest)
XCTAssertEqual(httpClient.postCallCounter, 5)
Expand Down Expand Up @@ -180,7 +179,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
metadata: metadata
)

await waitForExpectations(timeout: 5.0)
await fulfillment(of: [expectation, storageExpectation], timeout: 1.0)

// Then http client sends 5 apply flags batch request, containing 20 records each
let request = try XCTUnwrap(partiallyFailingHttpClient.data?.first as? ApplyFlagsRequest)
Expand Down Expand Up @@ -219,7 +218,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
httpClient.testMode = .success
await applier.apply(flagName: "flag2", resolveToken: "token1")

await waitForExpectations(timeout: 1.0)
await fulfillment(of: [networkExpectation], timeout: 1.0)

// Then 3 post calls are issued (one offline, one batch apply containing 2 reconrds)
XCTAssertEqual(httpClient.postCallCounter, 2)
Expand Down Expand Up @@ -263,7 +262,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
// With test mode .success
offlineClient.testMode = .success
await applier.apply(flagName: "flag2", resolveToken: "token1")
await waitForExpectations(timeout: 1.0)
await fulfillment(of: [storageExpectation, networkExpectation], timeout: 1.0)

// Then both requests are marked as sent in cache data
let cacheData = await cacheDataInteractor.cache
Expand Down Expand Up @@ -297,7 +296,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
metadata: metadata
)

await waitForExpectations(timeout: 1.0)
await fulfillment(of: [storageExpectation, networkExpectation], timeout: 1.0)

// Then storage has been cleaned
let storedData = try prefilledStorage.load(defaultValue: CacheData.empty())
Expand Down Expand Up @@ -326,7 +325,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
// When 100 apply calls are issued
// And all http client requests fails with .invalidResponse
await hundredApplyCalls(applier: applier, sameToken: true)
await waitForExpectations(timeout: 1.0)
await fulfillment(of: [networkExpectation], timeout: 1.0)

// Then strored data is empty
let storedData: CacheData = try XCTUnwrap(prefilledStorage.load(defaultValue: CacheData.empty()))
Expand Down Expand Up @@ -436,7 +435,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
// And http client request fails with .invalidResponse
await applier.apply(flagName: "flag1", resolveToken: "token1")

await waitForExpectations(timeout: 5.0)
await fulfillment(of: [networkExpectation], timeout: 1.0)

// Then 2 resolve event records are stored on disk
let storedData: CacheData = try XCTUnwrap(prefilledStorage.load(defaultValue: CacheData.empty()))
Expand Down Expand Up @@ -500,7 +499,7 @@ class FlagApplierWithRetriesTest: XCTestCase {
// When 100 apply calls are issued
// And all http client requests fails with .invalidResponse
await hundredApplyCalls(applier: applier, sameToken: true)
await waitForExpectations(timeout: 1.0)
await fulfillment(of: [networkExpectation], timeout: 1.0)

// Then 1 resolve event record is stored on disk
// And 200 flag event records are stored on disk
Expand Down

0 comments on commit 73ae9ce

Please sign in to comment.