RFR: 8315804: Open source several Swing JTabbedPane JTextArea JTextField tests [v5]

Alexey Ivanov aivanov at openjdk.org
Mon Sep 25 12:40:31 UTC 2023


On Mon, 18 Sep 2023 19:08:48 GMT, Damon Nguyen <dnguyen at openjdk.org> wrote:

>> test/jdk/javax/swing/JTabbedPane/bug4703690.java line 54:
>> 
>>> 52:     static volatile boolean focusButtonTwo = false;
>>> 53:     static volatile boolean switchToTabTwo = false;
>>> 54:     static volatile boolean focusButtonOne = false;
>> 
>> Assigning the default value is redundant.
>> 
>> Use CountDownLatch instead of boolean values:
>> 
>> 
>>     public void execute() {
>>         // Create robot
>> 
>>         two.requestFocus();
>> 
>>         if (!focusButtonTwo.await(1, TimeUnit.SECONDS)) {
>>             throw new RuntimeException("Button two didn't receive focus");
>>         }
>> 
>>         // Switch to tab two
>>         // do the click
>>         if (!switchToTabTwo.await(1, TimeUnit.SECONDS)) {
>>             throw new RuntimeException("Switching to tab two failed");
>>         }
>> 
>>         // Switch to tab one
>>         // do the click
>>         if (!focusButtonOne.await(1, TimeUnit.SECONDS)) {
>>             throw new RuntimeException("The 'Button 1' button doesn't have focus");
>>         }
>>     }
>> 
>> 
>> The test completes much faster because there are no unneeded delays.
>
> The test runs much faster with your changes. Appreciate the advice

Proper synchronisation has its benefits, yet implementing it is tiresome in UI tests, that's why we rely on delays. This case was just a perfect example where it's easy to do.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15747#discussion_r1335829061


More information about the client-libs-dev mailing list