Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8316388: Opensource five Swing component related regression tests #18259

Closed
wants to merge 4 commits into from

Conversation

azuev-java
Copy link
Member

@azuev-java azuev-java commented Mar 13, 2024

Cleaned up five more tests.

Continuation of #18184

Unfortunately one of the commits rendered the whole PR invalid so i closed it and restarting it here.
All comments from the previous review are addressed.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8316388: Opensource five Swing component related regression tests (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18259/head:pull/18259
$ git checkout pull/18259

Update a local copy of the PR:
$ git checkout pull/18259
$ git pull https://git.openjdk.org/jdk.git pull/18259/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18259

View PR using the GUI difftool:
$ git pr show -t 18259

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18259.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 13, 2024

👋 Welcome back kizune! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 13, 2024
@openjdk
Copy link

openjdk bot commented Mar 13, 2024

@azuev-java The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Mar 13, 2024
@mlbridge
Copy link

mlbridge bot commented Mar 13, 2024

Webrevs

test/jdk/javax/swing/JDesktopPane/bug4773378.java Outdated Show resolved Hide resolved
JInternalFrame jif;

Robot robot;
volatile boolean frameActivated = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
volatile boolean frameActivated = false;
private final CountDownLatch frameActivated = new CountDownLatch(1);

Comment on lines 68 to 71
synchronized (bug4773378.this) {
frameActivated = true;
bug4773378.this.notifyAll();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
synchronized (bug4773378.this) {
frameActivated = true;
bug4773378.this.notifyAll();
}
frameActivated.countDown();

Comment on lines 95 to 99
synchronized (this) {
while (!frameActivated) {
bug4773378.this.wait();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
synchronized (this) {
while (!frameActivated) {
bug4773378.this.wait();
}
}
frameActivated.await();

Using CountDownLatch is so much cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You like your countdown latches :) Ok, i will re-write this test with CDL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because 1 line of code replaces 4 lines of code and communicates what's happening much clearer than a synchronized block with a flag.

robot.keyRelease(KeyEvent.VK_F6);
robot.keyRelease(KeyEvent.VK_CONTROL);

Thread.sleep(2000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Thread.sleep(2000);
robot.waitForIdle();

Is it really necessary to wait for 2 seconds before shutting down the test.

According to JDK-4773378, NullPointerException was thrown when Ctrl+F6 was pressed. The waitForIdle method doesn't return until the event queue is empty which implies the keyboard events are handled. It saves nearly 2 seconds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Comment on lines 99 to 101
} catch (BadLocationException blex) {
passed = false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (BadLocationException blex) {
passed = false;
}
} catch (BadLocationException blex) {
throw new RuntimeException("Test failed", blex);
}

Throw exception preserving the original exception which will help analysing the failure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 117 to 120
safeSleep(3000);
if (!b.passed) {
throw new RuntimeException("Test failed.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
safeSleep(3000);
if (!b.passed) {
throw new RuntimeException("Test failed.");
}
robot.waitForIdle();

Wait until all events are processed. If test fails, it throws an exception on EDT; otherwise, the test is finished as soon as the event queue is empty. No need to waste 3 seconds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
robo.setAutoDelay(100);
robo.delay(1000);
Point p = frame.getLocationOnScreen();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, getLocationOnScreen should be called on EDT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens in the windowOpened method of the WindowAdapter. If window events arrive not on EDT then we have a whole other slew of problems :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ That's right!

Comment on lines +60 to +64
try (Writer writer = Files.newBufferedWriter(frameContentFile)) {
writer.write(frameContentString);
} catch (IOException ioe){
throw new RuntimeException("Could not create html file to embed", ioe);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move creating the file to main method before setting up GUI and let IOException escape from main.

Copy link
Member Author

@azuev-java azuev-java Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is try-with-resources so if i will do it in main i will have to add synchronizing and closing of writer which is a strange trade-off so i would have to do try block anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you need synchronisation?

        try (Writer writer = Files.newBufferedWriter(frameContentFile)) {
            writer.write(frameContentString);
        }

would write out the contents of the file and close the file handle. In setupGui, you would still use frameContentFile object only which is final and immutable, therefore it's thread-safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that's pretty much what i do here - except for the exception handling. I just do not see a reason to move it to main, it makes no difference except now the HTML creation will be split and harder to understand.

jep.setContentType("text/html");
String html = "<HTML> <BODY>" +
"<FRAMESET cols=\"100%\">" +
"<FRAME src=\"" + frameContentUrl + "\">" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"<FRAME src=\"" + frameContentUrl + "\">" +
"<FRAME src=\"" + frameContentFile.toUri()+ "\">" +

Isn't it enough? Alternatively, "file:/" + frameContentFile.toAbsolutePath() produces the same result as frameContentFile.toUri().toURL().

Another option is to convert the Path to URL in the main method before calling setupGUI and remove try-catch blocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, i do not mind the try/catch block and using URI instead of URL gives different result and i am not sure the original bug would be reproducible with URI which will make it a strange case of the regression test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Without the try-catch blocks, the code is simpler… Ensuring the updated test still reproduces the original issue is always a good thing to do, but running the updated with an old version of Java often requires modifying the source code again.

@openjdk
Copy link

openjdk bot commented Mar 13, 2024

@azuev-java This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8316388: Opensource five Swing component related regression tests

Reviewed-by: aivanov

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 58 new commits pushed to the master branch:

  • ad0f329: 8327787: Convert javax/swing/border/Test4129681.java applet test to main
  • a43c3cc: 8327826: Convert javax/swing/border/Test4243289.java applet test to main
  • 11a3673: 8328110: Allow simultaneous use of PassFailJFrame with split UI and additional windows
  • 1281e18: 8325613: CTW: Stale method cleanup requires GC after Sweeper removal
  • 49ce85f: 8327874: Convert javax/swing/JTree/4314199/bug4314199.java applet test to main
  • 481c866: 8327468: Do not restart close if errno is EINTR [macOS/linux]
  • 44aef38: 8327045: Consolidate -fvisibility=hidden as a basic flag for all compilation
  • fcf746d: 8328106: COMPARE_BUILD improvements
  • fadc4b1: 8327423: C2 remove_main_post_loops: check if main-loop belongs to pre-loop, not just assert
  • cff0747: 8326204: yield statements doesn't allow cast expressions with more than 1 type arguments
  • ... and 48 more: https://git.openjdk.org/jdk/compare/1f43fa0f8b0f956b41015e0ebc257e15a11ad99b...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

test/jdk/javax/swing/JEditorPane/bug4325606.java Outdated Show resolved Hide resolved
}
robo.setAutoDelay(100);
robo.delay(1000);
Point p = frame.getLocationOnScreen();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ That's right!

Co-authored-by: Alexey Ivanov <alexey.ivanov@oracle.com>
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 14, 2024
@azuev-java
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 15, 2024

Going to push as commit c05f8c7.
Since your change was applied there have been 89 commits pushed to the master branch:

  • b8dfeaf: 8328158: Convert java/awt/Choice/NonFocusablePopupMenuTest to automatic main test
  • d57bdd8: 8328165: improve assert(idx < _maxlrg) failed: oob
  • 128e60a: 8328037: Test java/util/Formatter/Padding.java has unnecessary high heap requirement after JDK-8326718
  • 06f4b7f: 8327756: Convert javax/swing/JSlider/4987336/bug4987336.java applet to main
  • 605800e: 8203867: Delete test java/awt/TrayIcon/DblClickActionEventTest/DblClickActionEventTest.html
  • 0943937: 8328218: Delete test java/awt/Window/FindOwner/FindOwner.html
  • f6390e5: 8328089: Automate javax/swing/JTable/4222153/bug4222153.java applet test
  • e8d1ba3: 8328228: Missing comma in copyright year for a few JColorChooser tests
  • be1dd27: 8328130: Remove applet usage from JColorChooser tests Test4759934
  • fab0edc: 8328121: Remove applet usage from JColorChooser tests Test4759306
  • ... and 79 more: https://git.openjdk.org/jdk/compare/1f43fa0f8b0f956b41015e0ebc257e15a11ad99b...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 15, 2024
@openjdk openjdk bot closed this Mar 15, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 15, 2024
@openjdk
Copy link

openjdk bot commented Mar 15, 2024

@azuev-java Pushed as commit c05f8c7.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants