On Fri, 18 Oct 2024 22:36:33 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:

>> This test follows the same pattern that I used in 
>> https://github.com/openjdk/jdk/pull/21474:
>> 
>> https://github.com/openjdk/jdk/pull/21474/files#diff-2a8cee50408407d7e24de4cb85f0921cfc5db7c215d3b29cf101a4050323e9a9R92
>
>> To ensure all the events in the queue are handled, I added 
>> `robot.waitForIdle()`.
> 
> This will flush events which were posted after the windows gained focus, but 
> before the patch the test flushed all events (including event to show the 
> window which might be asynchronous). My point is that this operation might be 
> longer that 1 second(one of the reason we have all that deleyas). So we 
> should waitForIdle first, then wait via delay or other sync_ops.

This will flush all the pending events in the queue, which includes events that 
were posted before the `windowGainedFocus` latch is released as well as events 
are posted afterwards.

There's no difference whether I place `waitForIdle` before or after.

If I place `robot.waitForIdle` before `windowGainedFocus.await`, then `await` 
immediately returns, that is the delay added by `await` is zero.

If I place `robot.waitForIdle` after `windowGainedFocus.await`, the main thread 
stops until the window gained focus event is delivered, after which 
`robot.waitForIdle` flushes the remaining events in the queue.

In both cases, there's a slight possibility `windowGainedFocus` is never 
triggered if the window didn't get focus for whatever reason…

On my Windows 11 laptop, the average time (over 20 runs of the `bug4323121` 
test)

* for `windowGainedFocus.await`: 12 ms
* for `robot.waitForIdle`: 36 ms
* or cumulatively: 48 ms

If I change the order of calls,

* for `robot.waitForIdle`: 51 ms
* for `windowGainedFocus.await`: 0 ms
* or cumulatively: 51 ms

Both versions align well — `robot.waitForIdle` takes about 50 ms. (The version 
where `waitForIdle` follows `await` is slightly quicker because `await` does 
nothing at all whereas `waitForIdle` posts events from its own copy of the 
queue for handling.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21475#discussion_r1809317633

Reply via email to