Skip to content

Tidy-up tests, introduce LoadingTest.TestApparatus & TestFetching.withStubDataStore #118

Merged
rtyley merged 1 commit intomainfrom
improve-testing
Oct 15, 2025
Merged

Tidy-up tests, introduce LoadingTest.TestApparatus & TestFetching.withStubDataStore #118
rtyley merged 1 commit intomainfrom
improve-testing

Conversation

@rtyley
Copy link
Member

@rtyley rtyley commented Oct 9, 2025

These improvements are partially motivated by the changes in this PR:

...as that PR adds a fetching.thenParsingWithKey() method to complement fetching.thenParsing(), it's good to tidy up the test for thenParsing() first, to make the subsequent introduction of testing on the sister-method thenParsingWithKey() method nice & small.

Changes

  • Create the com.gu.etagcaching.testkit package to contain useful functionality for tests
    • CountingParser - a parser that counts how many times it's used, so we can test we're not doing any unnecessary parsing
    • TestFetching moves into the testkit package, and gains TestFetching.withStubDataStore to let us create stub Fetching instances that will return whatever data we choose.
  • LoadingTest.TestApparatus added, to keep the checks for unnecessary-parsing concise.

Comment on lines -25 to +80
TolerateOldValueWhileRefreshing,
_.maximumSize(1).refreshAfterWrite(100.millis)
testApparatus.loading.onUpdate(update => updates.append(update)),
AlwaysWaitForRefreshedValue,
Copy link
Member Author

@rtyley rtyley Oct 9, 2025

Choose a reason for hiding this comment

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

This test ("provide callbacks that allow logging updates") was previously testing a bit more than just the target functionality, so it was more complex than it needed to be.

Switching to a FreshnessPolicy of AlwaysWaitForRefreshedValue (rather than TolerateOldValueWhileRefreshing) simplifies things because it means we always will receive the latest value, and don't need to add in artificial delays in order to get the right value.

@rtyley rtyley force-pushed the improve-testing branch 4 times, most recently from 0bb7706 to c3dc18a Compare October 10, 2025 16:42
@rtyley rtyley changed the title Add more tests, introduce TestFetching.withLookup Tidy-up tests, introduce LoadingTest.TestApparatus & TestFetching.withStubDataStore Oct 10, 2025
@rtyley rtyley marked this pull request as ready for review October 13, 2025 08:39
@rtyley rtyley requested a review from a team as a code owner October 13, 2025 08:39
@rtyley rtyley merged commit 70f6932 into main Oct 15, 2025
3 checks passed
@rtyley rtyley deleted the improve-testing branch October 15, 2025 15:27
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