Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMEL-17948: Force waiting before checking the asserts of the mock #7420

Merged
merged 1 commit into from Apr 12, 2022

Conversation

essobedo
Copy link
Contributor

Fix for https://issues.apache.org/jira/browse/CAMEL-17948

Motivation

While working on CAMEL-17945, I realized that the tests with the scope PER_CLASS leveraging the MockEndpoint to define their assertions can fail randomly because of a race condition issue. Indeed, with the current code, a message of a previous test method can potentially call the method countDown on the latch of the following test method causing unexpected behavior.

Modifications:

  • When at least one message is expected, always wait until the latch is released to prevent conflicts of messages of different test methods
  • Convert the counter to an AtomicInteger to guarantee the rest of an increment
  • Use a fixed value of the counter when getting the Processor to avoid potential race condition issues between 2 successive accesses
  • Add the new method expectedNoHeaderReceived to check if the received message has no headers (not related to the initial issue but needed for CAMEL-17945)
  • Add the new method assertFalse to check if a given predicate is false (not related to the initial issue but needed for CAMEL-17945)

@github-actions
Copy link
Contributor

⚠️ This PR changes Camel components and will be tested automatically.

@essobedo essobedo force-pushed the CAMEL-17948/race-condition-in-mockendpoint branch from bd5a729 to d7a5ff6 Compare April 12, 2022 12:57
@essobedo essobedo force-pushed the CAMEL-17948/race-condition-in-mockendpoint branch from d7a5ff6 to d2d0493 Compare April 12, 2022 13:06
@github-actions
Copy link
Contributor

✔️ Finished component verification: 0 component(s) test failed out of 2 component(s) tested

@github-actions
Copy link
Contributor

There are too many components to be tested in this PR, components were removed or the code needs a rebase: (22 likely to be tested)

1 similar comment
@github-actions
Copy link
Contributor

There are too many components to be tested in this PR, components were removed or the code needs a rebase: (22 likely to be tested)

@essobedo essobedo merged commit b7fcb13 into main Apr 12, 2022
@essobedo essobedo deleted the CAMEL-17948/race-condition-in-mockendpoint branch April 12, 2022 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants