Skip to content

refactor: test suite - #299

Open
vazarkevych wants to merge 20 commits into
refactor/client-corefrom
refactor/test-suite
Open

vazarkevych wants to merge 20 commits into
refactor/client-corefrom
refactor/test-suite

Conversation

@vazarkevych

@vazarkevych vazarkevych commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Base: refactor/client-core · stacked on #298; review after it, this diff only shows the test stage.

What

  • Mirrored packages. Tests move into the packages of the classes they test, for example ConditionEvaluatorTest → evaluators/, UrlUtilsTest → util/. They follow one style: a plain behaviour sentence in @DisplayName, a package-private method named after the behaviour, and // Given / // When / // Then bodies.
  • Contract tests.
    • GbCacheManager contract tests, shared with the cache modules through lib's test fixtures (java-test-fixtures). Those fixtures are not published: the testFixtures* variants are skipped in the component.
    • Features-repository contract tests, run against both GBFeaturesRepository and NativeJavaGbFeatureRepository.
  • Shared helpers. Test helpers move to testhelpers and the test fixtures.
  • fix(sandbox). FileCachingManagerImpl decodes the whole cache file strictly instead of joining lines and trimming. Cached payloads keep their line breaks and surrounding whitespace, and malformed bytes surface as a CharacterCodingException.
  • Cleanups. Comments that restated the code and a redundant Gson serialization are removed from five main classes, with no behaviour change.

main's new tests from #287, #292 and #235 are moved into this structure:

  • the $inGroup / $notInGroup cases join evaluators/ConditionEvaluatorTest as parameterized cases;
  • the failed-sticky-load cases join GrowthBookStickyBucketServiceFailureTest;
  • the markIfFirst / untrack / bounded-size cases join ExperimentTrackerTest;
  • the stickyBucketTimeout cases join OptionsValidatorTest.

The tests added on the lower PRs of the stack are written in this style in their new packages: repository isolation of the parsed features, plugin start after a failed construction, and the tracking plugin's close() waiting for a batch held on a caller-supplied executor.

Why

Tests were spread across packages that did not match the code, depended on reflection and real time, and duplicated setup. Mirrored packages, shared contract tests and common helpers make it clear where a test belongs, and run every cache adapter and both repositories against the same expectations.

Verification

./gradlew build javadoc on JDK 17, merged with current main:

Module Tests Failures Skipped
lib 3251 0 12
growthbook-cache-caffeine 33 0 5
growthbook-cache-jcache 27 0 0
growthbook-cache-redis 110 0 0

The skipped tests are failing-storage and shared-storage contract cases that do not apply to the in-memory, file and Caffeine adapters; two are charset cases that run only on a non-UTF-8 platform.

Six test classes that came from main are in the right packages but still use the older style:

Restyling them is left for a follow-up.

Checklist

  • PR title and commits follow Conventional Commits (feat:/fix: drive the release version)
  • Tests cover both valid and invalid cases (see the test style section in AGENTS.md)
  • No Java 9+ APIs (compiled with --release 8 on JDK 9+; the Java 8 matrix job is the backstop)
  • Release-please-owned files untouched (CHANGELOG.md, versions.txt, Version.java, gradle.properties version)
  • Public API of lib unchanged — or the change is deliberate and marked feat!: / BREAKING CHANGE:
  • New dependencies: none in lib (or explicitly approved); cache providers stay compileOnly

Volodymyr Nazarkevych added 5 commits November 1, 2026 00:01
Decode the whole file strictly instead of joining lines and trimming, so cached payloads keep their line breaks and surrounding whitespace, and malformed bytes surface as a CharacterCodingException.
…ntract tests

Move tests into packages that mirror lib's main sources, add GbCacheManager and features-repository contract tests (shared with the cache modules via lib's test fixtures, which are not published), and add shared test helpers.
# Conflicts:
#	lib/src/test/java/growthbook/sdk/java/ConditionEvaluatorTest.java
#	lib/src/test/java/growthbook/sdk/java/StickyBucketServiceFailureTest.java
#	lib/src/test/java/growthbook/sdk/java/multiusermode/ExperimentTrackerTest.java
#	lib/src/test/java/growthbook/sdk/java/multiusermode/GrowthBookClientTest.java
#	lib/src/test/java/growthbook/sdk/java/multiusermode/configurations/OptionsValidatorTest.java
The @AfterEach hook appended every served request to /tmp/gbaudit/wm.log, a leftover from local debugging that fails on any machine without that directory.
@vazarkevych
vazarkevych changed the base branch from main to refactor/client-core November 19, 2026 16:05
@vazarkevych
vazarkevych added this pull request to stack #297 November 19, 2026 16:05
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] This PR appears safe to merge.

Reviews (8) · Last reviewed commit: "Merge branch 'refactor/client-core' into..." · Reviewed by Greptile

@greptile-apps

This comment has been minimized.

Volodymyr Nazarkevych added 3 commits November 20, 2026 09:45
WireMock 2.35 notifies request listeners before it records the request
in its journal, so awaiting the listener and then reading the journal
raced and failed intermittently on CI. Record the track requests in the
listener itself and read them from there.
The GbCacheManager contract and InMemoryCachingManagerImplTest bracketed
writes between two wall-clock reads, so a clock adjustment could fail a
correct adapter. The contract now owns a mutable clock that adapters
taking a Clock read from, and asserts the exact reported write time;
FileCachingManagerImpl, whose times come from file mtimes, compares
against the file's own mtime. InMemoryCachingManagerImpl gains a
package-private Clock constructor; its public constructor is unchanged.
# Conflicts:
#	lib/src/test/java/growthbook/sdk/java/NativeJavaGbFeatureRepositoryMainBehaviorTest.java
#	lib/src/test/java/growthbook/sdk/java/evaluators/internal/ForcedValuesTest.java
#	lib/src/test/java/growthbook/sdk/java/multiusermode/internal/FeatureValuesTest.java
#	lib/src/test/java/growthbook/sdk/java/repository/LocalGbFeatureRepositoryBehaviorTest.java
#	lib/src/test/java/growthbook/sdk/java/repository/LruETagCacheTest.java
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

# Conflicts:
#	lib/src/test/java/growthbook/sdk/java/NativeJavaGbFeatureRepositoryRefreshTest.java
#	lib/src/test/java/growthbook/sdk/java/plugin/PluginIntegrationTest.java
#	lib/src/test/java/growthbook/sdk/java/repository/LocalGbFeatureRepositoryBehaviorTest.java
@vazarkevych vazarkevych mentioned this pull request Nov 25, 2026
6 tasks done
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

…resh never runs

Every poll returning null made both assertSame checks pass, so a
scheduler dropping all forced refreshes went unnoticed.
The diagnostics provider read the wall clock, so the tests built their
fetch, cache and expiry times from it too; a clock adjustment between
the two reads could break the exact age assertions. The provider and
the client's initialization-error timestamp now take an injectable
Clock (system UTC by default), and the tests pass a fixed one.
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

Moves the repository-core case into the lifecycle test that holds the
other SSE initialization cases, and lets InMemoryCacheManager report
per-key last-updated timestamps (none by default).
…est fails

A failed awaitFetchStarted skipped gate.countDown, leaving a non-daemon
loader blocked forever. The gate release, cache shutdown and loader
cleanup now run in finally, and the loader is a daemon thread.
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

This branch has not been deployed

No deployments
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.

1 participant