Skip to content

Conversation

@Bouncheck
Copy link

@Bouncheck Bouncheck commented Sep 24, 2025

The main issue is that it uses cache.size().
While it may not be a bad idea to use that, the documentation mentions that it returns an approximate size of the cache. CqlPrepareAsyncProcessor actually invalidates the prepare requests that finish with errors (see process method). Such is the case with this test. The PreparedStatement gets cached for a really short period and then invalidated because of the exception.
Depending on the exact timings it would be correct for the cache to report either size 0 or size 1. Additionally the moment when the size gets updated may differ from the moments modifications to the cache contents are made.

This change is a quick workaround that should
achieve the same end result as the setup in PreparedStatementCachingIT. Here we use reflection to forcibly change the cache used by the request processor. Same type, but has removal listener added to it. Instead of relying on the uncertain cache size the test will listen for the removal from the cache.

The alternative would be reimplementing similar setup as in PreparedStatementCachingIT with some changes. That means having a test version of DefaultDriverContext, CqlPrepareAsyncProcessor, SessionBuilder and necessary methods, so that we could inject the listener without the reflection.

The other option is moving this test method to the PreparedStatementCachingIT, but then the cache's remove callback which is used there throughout the class needs to be adjusted specifically for this method.

Fixes #514

The main issue is that it uses `cache.size()`.
While it may not be a bad idea to use that, the documentation
mentions that it returns an approximate size of the cache.
`CqlPrepareAsyncProcessor` actually invalidates the prepare requests that
finish with errors (see `process` method). Such is the case with this test.
The `PreparedStatement` gets cached for a really short period and then
invalidated because of the exception.
Depending on the exact timings it would be correct for the cache to report
either size 0 or size 1. Additionally the moment when the size gets updated
may differ from the moments modifications to the cache contents are made.

This change is a quick workaround that should
achieve the same end result as the setup in PreparedStatementCachingIT.
Here we use reflection to forcibly change the cache used by the
request processor. Same type, but has removal listener added to it.
Instead of relying on the uncertain cache size the test will listen for
the removal from the cache.

The alternative would be reimplementing similar setup as in
PreparedStatementCachingIT with some changes. That means
having a test version of DefaultDriverContext, CqlPrepareAsyncProcessor,
SessionBuilder and necessary methods, so that we could inject the listener
without the reflection.

The other option is moving this test method to the PreparedStatementCachingIT,
but then the cache's remove callback which is used there throughout the class
needs to be adjusted specifically for this method.
@Bouncheck Bouncheck self-assigned this Sep 24, 2025
@Bouncheck Bouncheck changed the title 3.x: Stabilize will_cache_invalid_cql test method. 4.x: Stabilize will_cache_invalid_cql test method. Sep 24, 2025
@Bouncheck
Copy link
Author

So far around 100 runs completed without an issue.

@dkropachev dkropachev merged commit ab2665f into scylladb:scylla-4.x Sep 25, 2025
10 of 11 checks passed
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.

4.x: PreparedStatementCancellationIT.will_cache_invalid_cql can fial

2 participants