Axon testcases failes while adding cache config to aggregete

Hi team,

when I update the annotation of the aggregate class from @Aggregate to @Aggregate(cache = “aggregateCache”). Test cases got fails.
But when I re-run those failed test cases, It got passed.

Here is the configuration.

@Bean
    public Cache aggregateCache() {
        return new WeakReferenceCache();
    }

Can you suggest me any solution?
(Note: Need for @Aggregate(cache = “aggregateCache”)* annotation is to increase performance. Test cases are executing faster.)

What kind of tests are you running? Do they include a Spring Application Context?

Hi @allardbz
These test cases are related to Automation testing.
I have used these 2 annotations.
@RunWith(SerenityRunner.class)
@Concurrent(threads = “4”)

Here, they are executing previously, when I simply use @Aggregate annotation to Aggregate class.

Most likely has to do with state being shared across test cases. The cache will hold entries at the start of a test as they were left there by the previous test. You may want to use removeAll in a beforeEach similarly to how you are probably resetting database state.
Do you use AxonServer in these tests?

Axon server is not used.
Here, I more case arise, when the records in eventstore (mongodb) reaches more than 5000, then it affects performance (testcase execution tooks longer time).

Is Mongo cleared in between test cases?

No @allardbz
Could you suggest me configuration

I don’t have much to go on here… All I know is that “some tests fail.” I don’t know what the tests do nor how they fail. The fact that they do pass when re-running them individually is a clear hint that the test cases are affecting each other’s state.

My recommendation is to check for tests that don’t expect other tests to change the state simultaneously. Since you are apparently running these tests concurrently, it may very well be that adding the cache causes some side effects in the tests.