jeantil commented on code in PR #2416: URL: https://github.com/apache/james-project/pull/2416#discussion_r1768938465
########## server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java: ########## @@ -457,24 +454,25 @@ default void removeShouldNotFailWhenBrowsingIterating() throws Exception { @Test default void browseShouldNotFailWhenConcurrentRemoveWhenIterating() throws Exception { - enQueue(defaultMail() - .name("name1") - .build()); - enQueue(defaultMail() - .name("name2") - .build()); - enQueue(defaultMail() - .name("name3") - .build()); + // We use a large number of emails so that the probability of the remove being propagated + // through the queue is high enough that the test is not flaky. + IntStream.range(0, 100).forEach( + Throwing.intConsumer(i -> + enQueue(defaultMail() + .name("name" + i) + .build()) + ).sneakyThrow() + ); ManageableMailQueue.MailQueueIterator items = getManageableMailQueue().browse(); - items.next(); + items.next(); // we consume 1 here - getManageableMailQueue().remove(ManageableMailQueue.Type.Name, "name2"); + getManageableMailQueue().remove(ManageableMailQueue.Type.Name, "name99"); - awaitRemove(); - assertThatCode(() -> Iterators.consumingIterator(items)).doesNotThrowAnyException(); + assertThatCode( + () -> assertThat(consumeIterator(items)).isEqualTo(98) // and 998 here so 999 in total + ).doesNotThrowAnyException(); Review Comment: interestingly, this test fails except for the pulsar implementation. Most implementations will return the removed item if the browse has been started before the item is removed. The pulsar implementation is able to filter it out even from an operating iterator. I am considering lowering the constraint here with this code ``` assertThatCode( // the remove may or may not be applied to an already started iterator // as long as it doesn't make the iterator crash () -> assertThat(consumeIterator(items)).isGreaterThanOrEqualTo(98).isLessThan(100) ).doesNotThrowAnyException(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org