Skip to content

test: harden clear() namespace isolation, tag invalidation and deleteItem() return value - #124

Open
GromNaN wants to merge 3 commits into
php-cache:masterfrom
GromNaN:test/namespace-isolation-and-tag-invalidation
Open

test: harden clear() namespace isolation, tag invalidation and deleteItem() return value#124
GromNaN wants to merge 3 commits into
php-cache:masterfrom
GromNaN:test/namespace-isolation-and-tag-invalidation

Conversation

@GromNaN

@GromNaN GromNaN commented Aug 24, 2026

Copy link
Copy Markdown

Three small additions to the contract, found while implementing a PSR-6 adapter for MongoDB (symfony/symfony#65468). In each case the current tests pass on an implementation that is actually wrong.

clear() must not touch another namespace on the same storage

When several pools share a single storage, a table or a collection for instance, clearing one pool must only remove its own keys. Nothing checks that today, because the tests only ever use one pool.

CachePoolTest gains an optional createCachePoolWithOtherNamespace(), which returns a second pool on the same storage under another namespace. It returns null by default, and the new testClearDoesNotAffectOtherNamespaces is then skipped, so existing implementations are unaffected. When a pool is given, the test writes the same key in both, clears the first one, and checks that the second still holds its own value.

testInvalidateTags now uses disjoint tags

key was tagged with tag1 and tag2 while key2 was tagged with tag1, so invalidating tag1 alone was enough to pass. Each item now carries a single distinct tag, and a third item, tagged with none of the invalidated tags, checks that the invalidation does not reach too far.

deleteItem() return value on a tagged item

testRemoveTagWhenItemIsRemoved ignored what deleteItem() returned. It is now asserted to be true.

Add an optional createCachePoolWithOtherNamespace() extension point and a test that saves the same key in two pools sharing the same storage under different namespaces. The test is skipped when the implementation returns null.
The test used overlapping tags, so an implementation that only invalidates the first tag of the list still passed. Use disjoint tags plus a control item tagged with none of the invalidated tags.
The return value was ignored, so an implementation returning false while the deletion actually happened still passed.
@GromNaN
GromNaN force-pushed the test/namespace-isolation-and-tag-invalidation branch from 9f64b72 to e61cecb Compare August 24, 2026 09:59
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