test(ads-client): assert mockito expectations to prevent silent false-positives#7347
Open
Almaju wants to merge 1 commit intomozilla:mainfrom
Open
test(ads-client): assert mockito expectations to prevent silent false-positives#7347Almaju wants to merge 1 commit intomozilla:mainfrom
Almaju wants to merge 1 commit intomozilla:mainfrom
Conversation
…-positives Mockito mocks set up with .expect(N) only verify the call count when .assert() is invoked — without it, tests pass even if the expected network interactions never happen. Pair every interaction-verifying mock setup with an explicit .assert(). Also fix test_fetch_ads_cache_hit_skips_network, which passed None for the cache and so always hit the network twice; the missing .assert() hid this. The test now uses a real HttpCache so the cache-hit path is actually exercised.
copyrighthero
approved these changes
May 5, 2026
Contributor
copyrighthero
left a comment
There was a problem hiding this comment.
Verified locally that the test ran successfully!
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some ads-client tests configured mockito mocks with
.expect(N)to declare an expected request count, but never called.assert()to verify it. Without the assert, mockito does not enforce the expectation, so tests pass even when the underlying behavior is wrong.This PR pairs every interaction-verifying mock setup with an explicit
.assert()call acrossmars.rs,http_cache.rs, andclient.rs(including the ignoredtest_record_click_invalidates_cache).While doing this, the missing
.assert()surfaced a real silent false-positive:mars::tests::test_fetch_ads_cache_hit_skips_networkwas constructing the test client withNonefor the cache, so both calls hit the network and the cache-hit path the test claimed to verify was never actually exercised. The test now constructs a realHttpCacheso the second call serves from cache, and the.assert()enforces that only one network request was made.A couple of duplicate-mock setups in
http_cache.rs(test_refresh_policy_always_uses_network_then_caches,test_expired_entry_is_a_miss_on_next_send) were collapsed into a single mock withexpect(2). The bodies were never inspected, and a single mock makes the network call count directly verifiable.test_not_cacheable_no_storewas tightened to assert both calls hit the network asMissNotCacheable.Test plan
cargo test -p ads-client --lib— all 77 tests pass (1 ignored, unchanged)make_test_client(Some(cache))change intest_fetch_ads_cache_hit_skips_networkcauses the test to fail with "Expected 1 request(s) ... but received 2"