Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Tests: improve flaky tests #3163

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Logging/Strings/NetworkStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extension NetworkStrings: LogMessage {

#if DEBUG
case let .api_request_forcing_server_error(request):
return "Returning fake HTTP 500 error for '\(request.description)'"
return "Returning fake HTTP 500 error for \(request.description)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ended up with double quotes:

Returning fake HTTP 500 error for 'POST '/v1/receipts''


case let .api_request_forcing_signature_failure(request):
return "Returning fake signature verification failure for '\(request.description)'"
Expand Down
22 changes: 19 additions & 3 deletions Sources/Logging/Strings/OfflineEntitlementsStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum OfflineEntitlementsStrings {
case computing_offline_customer_info_for_consumable_product
case computing_offline_customer_info
case computing_offline_customer_info_failed(Error)
case computed_offline_customer_info(EntitlementInfos)
case computed_offline_customer_info([PurchasedSK2Product], EntitlementInfos)
case computed_offline_customer_info_details([PurchasedSK2Product], EntitlementInfos)

case purchased_products_fetching
case purchased_products_fetching_too_slow
Expand Down Expand Up @@ -79,8 +80,23 @@ extension OfflineEntitlementsStrings: LogMessage {
return "Error computing offline CustomerInfo. Will return original error.\n" +
"Creation error: \(error.localizedDescription)"

case let .computed_offline_customer_info(entitlements):
return "Computed offline CustomerInfo with \(entitlements.active.count) active entitlements."
case let .computed_offline_customer_info(products, entitlements):
return "Computed offline CustomerInfo from \(products.count) products " +
"with \(entitlements.active.count) active entitlements."

case let .computed_offline_customer_info_details(products, entitlements):
let productIDs = products
.lazy
.map(\.productIdentifier)
.joined(separator: ", ")
let entitlements = entitlements
.active
.values
.lazy
.map(\.identifier)
.joined(separator: ", ")

return "Purchased products: [\(productIDs)]. Active entitlements: [\(entitlements)]."

case .purchased_products_fetching:
return "PurchasedProductsFetcher: fetching products from StoreKit"
Expand Down
9 changes: 6 additions & 3 deletions Sources/Networking/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ class HTTPClient {
#if DEBUG
guard !self.systemInfo.dangerousSettings.internalSettings.forceServerErrors else {
Logger.warn(Strings.network.api_request_forcing_server_error(request))
completionHandler?(
.failure(.errorResponse(Self.serverErrorResponse, .internalServerError))
)
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intent behind this isn't obvious at first glance so let's make sure to add a comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I always think it's in git history but that's easily lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

completionHandler?(
.failure(.errorResponse(Self.serverErrorResponse, .internalServerError))
)
}

return
}
#endif
Expand Down
7 changes: 6 additions & 1 deletion Sources/OfflineEntitlements/OfflineCustomerInfoCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class OfflineCustomerInfoCreator {

let offlineCustomerInfo = creator(products, mapping, userID)

Logger.info(Strings.offlineEntitlements.computed_offline_customer_info(offlineCustomerInfo.entitlements))
Logger.info(Strings.offlineEntitlements.computed_offline_customer_info(
products, offlineCustomerInfo.entitlements
))
Logger.debug(Strings.offlineEntitlements.computed_offline_customer_info_details(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I improved these logs to be able to debug future issues here. Initially I wasn't sure if PurchasedProductsFetcher was working correctly.

products, offlineCustomerInfo.entitlements
))

return offlineCustomerInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ class OfflineCustomerInfoResponseHandlerTests: BaseCustomerInfoResponseHandlerTe

self.logger.verifyMessageWasLogged(Strings.offlineEntitlements.computing_offline_customer_info, level: .info)
self.logger.verifyMessageWasLogged(
Strings.offlineEntitlements.computed_offline_customer_info(Self.offlineCustomerInfo.entitlements),
Strings.offlineEntitlements.computed_offline_customer_info([Self.purchasedProduct],
Self.offlineCustomerInfo.entitlements),
level: .info
)
}
Expand Down