chore(sync-service): Fix flakey Publisher tests #2851
Merged
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.
These tests can occasionally fail with:
The race condition occurs if the TestSubscriber receives the
:finish_processing_messagemessage before it receives the publisher call, in which case it swallows the message sincehandle_infois not implemented on TestSubscriber. A GenServer would log that a message had been received and not handled, but asuse GenServerwas omitted from the TestSubscriber the message was swallowed silently.This PR:
use GenServerto the TestSubscriber as this is best practice (the race condition would have been obvious had it been included in the first place):message_receivedfrom each of the subscribers before sending:finish_processing_message. This eliminates the race condition.eventtomessagefor consistencyCredit to ChatGPT which worked out what the race condition was. It's solution was terrible, but the hard part was knowing what the race condition was, so that was super helpful.