RFR: 8321124: java/util/stream/GatherersTest.java times out [v2]

Alan Bateman alanb at openjdk.org
Mon Dec 4 08:57:45 UTC 2023


On Sun, 3 Dec 2023 09:50:53 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> test/jdk/java/util/stream/BuiltInGatherersTest.java line 331:
>> 
>>> 329:                                     case Integer n when n == config.streamSize - 1 -> {
>>> 330:                                         awaitSensibly(firstReady);
>>> 331:                                         while(tasksWaiting.getQueueLength() < tasksToCancel) {
>> 
>> @AlanBateman This is the only part of this I really don't like. Any better suggestion as to "wait for N things waiting" in a test? 🤔
>
>> @AlanBateman This is the only part of this I really don't like. Any better suggestion as to "wait for N things waiting" in a test? 🤔
> 
> Semaphore::getQueueLength is more for monitoring purposes so the usage does seem a bit unusual here. There are a number of ways this could be done, maybe the simplest is for tasksWaiting to be an AtomicInteger and have the default just increment it and sleep-for-a-day.

> @AlanBateman Unfortunately that doesn't really work as there's then a window between incrementing the counter and going to sleep. So while it might execute correctly in 99.9999% of cases I don't want to have a jbs bug filed which will be one of those things where you can't recall it 6-12 months down the line 😓

Thread.sleep throws if called with the interrupt status set so a cancel in the window between before the sleep should be okay. I think in this case, it's whatever is simplest is reliable and easy to read/maintain.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16928#discussion_r1413551130


More information about the core-libs-dev mailing list