[ 
https://issues.apache.org/jira/browse/CAMEL-19549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18091585#comment-18091585
 ] 

Torsten Mielke commented on CAMEL-19549:
----------------------------------------

Thanks for the guidance [~orpiske].
I submitted PR https://github.com/apache/camel/pull/24247

Here a summary of the changes:
- 
{{src/test/java/org/apache/camel/processor/aggregator/DistributedCompletionIntervalTest.java}}
  No need to wait 2 secs before sending msgs. Camel routes will be fully 
initialised when the test methods get executed
  {code:java}
  // ensure messages are send after the 1s
  // Thread.sleep(2000);
  {code}
- {{src/test/java/org/apache/camel/language/XPathRouteConcurrentTest.java}}
   test method {{testXPathTwoMessagesNotSameTime()}} does not really add any 
additional test logic as {{template.sendBody()}} is a sync call.
   removed the test method entirely
-  
{{src/test/java/org/apache/camel/component/direct/DirectProducerBlockingTest.java}}
    use CountDownLatch to synchronize events rather than Thread.sleep()
- 
{{src/test/java/org/apache/camel/component/seda/FileSedaShutdownCompleteAllTasksTest.java}}
   sleep() is not necessary and can be removed
- 
{{src/test/java/org/apache/camel/component/validator/ValidatorEndpointClearCachedSchemaTest.java}}
   use CountDownLatch to synchronize events rather than Thread.sleep()
- 
{{src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java}}
   use awaitility to wait for condition, replacing Thread.sleep()
- {{src/test/java/org/apache/camel/impl/StopTimeoutRouteTest.java}}
   remove CountDownLatch processingDone as it is never evaluated
- 
{{src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliverWithDelayBlockingTest.java}}
   replace Thread.sleep() with CountDownLatch
- {{src/test/java/org/apache/camel/processor/IdempotentConsumerAsyncTest.java}}
   Thread.sleep) call can be removed without changing the test logic
- 
{{src/test/java/org/apache/camel/processor/RecipientListWithSimpleExpressionTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- {{src/test/java/org/apache/camel/processor/ResequencerTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- {{src/test/java/org/apache/camel/processor/ShutdownDeferTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- 
{{src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionIntervalTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- 
{{src/test/java/org/apache/camel/processor/enricher/PollEnricherNoResourceTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- 
{{src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyKeepOpenOnInitTest.java}}
   Thread.sleep() call can be removed without changing the test logic
- 
{{src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyTest.java}}
   Thread.sleep() call can be removed without changing the test logic


> camel-core: replace Thread.sleep in tests
> -----------------------------------------
>
>                 Key: CAMEL-19549
>                 URL: https://issues.apache.org/jira/browse/CAMEL-19549
>             Project: Camel
>          Issue Type: Task
>          Components: camel-core, tests
>    Affects Versions: 4.0.0
>            Reporter: Otavio Rodolfo Piske
>            Assignee: Torsten Mielke
>            Priority: Minor
>              Labels: easy, help-wanted
>
> We have many tests which use Thread.sleep for synchronization. This is bug 
> prone and can introduce flakiness when running on environments with different 
> capacities.
> Ideally we should replace these with:
>  * [Awaitility|http://www.awaitility.org/]
>  * Java's native syncronization mechanism (Latches, Phasers, Locks, etc)
>  * Nothing (i.e.; in some cases the sleep can simply be removed)
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to