Hi Sergey,
Just repeating the same answer in this thread as well.

Here is my understanding of waitForIdle() - it ensures that all the events on 
the EDT are pushed, and it has a huge wait time of 10seconds, which should 
mostly guarantee that there are no pending events on the EDT till the function 
is executed. And it mostly works on all platforms. The test case failed on OEL, 
whereas it passed on Windows and Linux. I haven't checked for Mac, but most 
likely it would work there too. 
The testcase in question tries to paint the window, and then picks the color 
from a particular location on screen. The function bug8024864::showTestUI has 
frame.setVisible(true) as its last statement, which should ultimately generate 
a native paint event. Now waitForIdle will ensure that, that event has been 
posted, but paint/repaint will involve some work down the OS level. Now, it 
could be possible that, the scheduler might choose to suspend the EDT thread 
and run the main thread, which checks for the pixel color on the screen and it 
might fail.
So, although waitForIdle guarantees dispatch of all the events from the EDT, it 
doesnot guarantee that they have been processed. 
Hence the changes I have made to make sure that the window has been drawn on to 
the screen.

As a sidenote, I was looking into the code, and found this kind of code in 
SunToolkit.realSync:
            int iters = 0;
            while (iters < MIN_ITERS) {
                syncNativeQueue(timeout);
                iters++;
            }

The MIN_ITERS is set as 0, so this code never executes. Either the loop should 
be changed to do-while, or should be removed. There is another loop which does 
the actual work:
            while (syncNativeQueue(timeout) && iters < MAX_ITERS) {
                iters++;
            }

Let me know your thoughts on this.

Thanks,
Krishna

-----Original Message-----
From: Sergey Bylokhov 
Sent: Friday, January 19, 2018 4:28 AM
To: Krishna Addepalli <krishna.addepa...@oracle.com>; swing-dev@openjdk.java.net
Subject: Re: <Swing Dev> [11][JDK-8137101][TEST_BUG] 
javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java failure due to timing

Hi, Krishna.
I have the same question as in another bug: why robot.waitForIdle() does not 
work?

On 18/01/2018 10:44, Krishna Addepalli wrote:
> Hi All,
> 
> Please review a fix for following bug:
> 
> Bug: JDK-8137101 : https://bugs.openjdk.java.net/browse/JDK-8137101
> 
> Webrev: http://cr.openjdk.java.net/~kaddepalli/8137101/webrev00/
> 
> The problem is that EDT doesnot get enough time to show the window on 
> screen before the next function tries to pick colors from the screen.
> The solution is to use CountDownLatch to make the main thread wait 
> deterministically before trying to pick colors.
> 
> Thanks,
> 
> Krishna
> 


--
Best regards, Sergey.

Reply via email to