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.
This PR is to fix a flaky test
o.moquette.broker.MemoryRetainedRepositoryTest#testRetainedOnTopicReturnsWildcardTopicMatch
in modulebroker
.Test failures
Root cause
In line 84 of the test file,
retainedMessages = repository.retainedOnTopic("foo/#");
callsretainedOnTopic
from broker/src/main/java/io/moquette/broker/MemoryRetainedRepository.java.In line 33 of the main class file provided,
storage
is defined as aConcurrentHashMap
, its keys are not in sorted order. Consequently, in line 58, when theretainedOnTopic
method callsstorage.entrySet()
, the returned elements' order is non-deterministic. This leads to inconsistencies in the order of the elements inmatchingMessages
.When it is returned to the test, the assertion in lines 87-88 (in the test file) assumes the orders are consistent, causing the test to fail.
Fix
To fix the flakiness, we can either change the test code or change the main code:
retainedMessages
before making assertions of them in the test, which is the code change in this PR.ConcurrentSkipListMap
instead ofConcurrentMap
.ConcurrentSkipListMap
is sorted and thread-safe. If you prefer the code changes of the following PR: https://github.com/dserfe/moquette/pull/2/files, please let me know!