Skip to content

Logging: avoid logging "updating offerings" when request is cached#2896

Merged
NachoSoto merged 1 commit into
nacho/sdk-3243-422s-fix-bug-where-transactions-are-misidentified-asfrom
offerings-log-once
Jul 26, 2023
Merged

Logging: avoid logging "updating offerings" when request is cached#2896
NachoSoto merged 1 commit into
nacho/sdk-3243-422s-fix-bug-where-transactions-are-misidentified-asfrom
offerings-log-once

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

I noticed this in our logs:

[offering] DEBUG: ℹ️ No cached Offerings, fetching from network
[purchases] VERBOSE: Updating all caches
[offering] DEBUG: ℹ️ Offerings cache is stale, updating from network in foreground
[offering] DEBUG: ℹ️ Offerings cache is stale, updating from network in foreground
[network] DEBUG: ℹ️ Network operation 'GetOfferingsOperation' found with the same cache key 'GetOfferingsOpe...'. Skipping request.
[network] DEBUG: ℹ️ GetOfferingsOperation: Started

The double "updating from network" can be confusing, so this fixes it so it's only logged if the request will actually be started. Also added/updated our tests to verify the correct logs as well as caching behavior.

I noticed this in our logs:
```
[offering] DEBUG: ℹ️ No cached Offerings, fetching from network
[purchases] VERBOSE: Updating all caches
[offering] DEBUG: ℹ️ Offerings cache is stale, updating from network in foreground
[offering] DEBUG: ℹ️ Offerings cache is stale, updating from network in foreground
[network] DEBUG: ℹ️ Network operation 'GetOfferingsOperation' found with the same cache key 'GetOfferingsOpe...'. Skipping request.
[network] DEBUG: ℹ️ GetOfferingsOperation: Started
```

The double "updating from network" can be confusing, so this fixes it so it's only logged if the request will actually be started.
Also added/updated our tests to verify the correct logs as well as caching behavior.
@NachoSoto NachoSoto requested a review from a team July 26, 2023 10:22
self.backendConfig.addCacheableOperation(
with: factory,
withRandomDelay: randomDelay,
withRandomDelay: isAppBackgrounded,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This decision makes more sense in this "API" type than in OfferingsManager.

)
}

func testOfferingsAreOnlyFetchedOnceOnSDKInitialization() async throws {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New test.

func testOfferingsAreOnlyFetchedOnceOnSDKInitialization() async throws {
self.logger.verifyMessageWasLogged(Strings.offering.offerings_stale_updating_in_foreground,
level: .debug,
expectedCount: 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was the failing test that this fixes.

expectedCount: 1)
self.logger.verifyMessageWasLogged("GetOfferingsOperation: Started",
level: .debug,
expectedCount: 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But this also doesn't hurt to verify.

@codecov

codecov Bot commented Jul 26, 2023

Copy link
Copy Markdown

Codecov Report

Merging #2896 (25346af) into nacho/sdk-3243-422s-fix-bug-where-transactions-are-misidentified-as (71ba0da) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@                                           Coverage Diff                                           @@
##           nacho/sdk-3243-422s-fix-bug-where-transactions-are-misidentified-as    #2896      +/-   ##
=======================================================================================================
+ Coverage                                                                86.58%   86.60%   +0.02%     
=======================================================================================================
  Files                                                                      217      217              
  Lines                                                                    15531    15533       +2     
=======================================================================================================
+ Hits                                                                     13447    13453       +6     
+ Misses                                                                    2084     2080       -4     
Files Changed Coverage Δ
Sources/Networking/OfferingsAPI.swift 100.00% <100.00%> (ø)
Sources/Purchasing/OfferingsManager.swift 93.44% <100.00%> (-0.11%) ⬇️

... and 2 files with indirect coverage changes

@NachoSoto NachoSoto merged this pull request into nacho/sdk-3243-422s-fix-bug-where-transactions-are-misidentified-as Jul 26, 2023
@NachoSoto NachoSoto deleted the offerings-log-once branch July 26, 2023 16:00
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Ugh damn it I merged this in the wrong branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants