Skip to content

JDK-8326389: [test] improve assertEquals failure output#17952

Closed
MBaesken wants to merge 4 commits intoopenjdk:masterfrom
MBaesken:JDK-8326389
Closed

JDK-8326389: [test] improve assertEquals failure output#17952
MBaesken wants to merge 4 commits intoopenjdk:masterfrom
MBaesken:JDK-8326389

Conversation

@MBaesken
Copy link
Member

@MBaesken MBaesken commented Feb 21, 2024

Currently assertEquals has in the failure case sometimes confusing output like :

java.lang.RuntimeException: VM output should contain exactly one RTM locking statistics entry for method compiler.rtm.locking.TestRTMTotalCountIncrRate$Test::lock: expected 0 to equal 1
at jdk.test.lib.Asserts.fail(Asserts.java:634)
at jdk.test.lib.Asserts.assertEquals(Asserts.java:205)

(I don't think we really expected that for some reason 0 equals 1)
This should be improved.


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-8326389: [test] improve assertEquals failure output (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17952

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 21, 2024

👋 Welcome back mbaesken! 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 Feb 21, 2024
@openjdk
Copy link

openjdk bot commented Feb 21, 2024

@MBaesken The following label will be automatically applied to this pull request:

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Feb 21, 2024
@mlbridge
Copy link

mlbridge bot commented Feb 21, 2024

Webrevs

@RealCLanger
Copy link
Contributor

I think it is a good idea to improve this. I was irritated by that output more than once.

Maybe a better message would be ... "..." is not equal to "..." ?

@MBaesken
Copy link
Member Author

I think it is a good idea to improve this. I was irritated by that output more than once.

Maybe a better message would be ... "..." is not equal to "..." ?

Thanks , I adjusted the output .

@MBaesken
Copy link
Member Author

now the error output is like
java.lang.RuntimeException: VM output should contain two rtm locking statistics entries for method compiler.testlibrary.rtm.XAbortProvoker::forceAbort: object "0" is not equal to "2"

looks much better to me.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks good from my end.

@openjdk
Copy link

openjdk bot commented Feb 23, 2024

@MBaesken 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:

8326389: [test] improve assertEquals failure output

Reviewed-by: clanger, jpai

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 74 new commits pushed to the master branch:

  • 4dd6c44: 8326529: JFR: Test for CompilerCompile events fails due to time out
  • 33f2382: 8325807: Shenandoah: Refactor full gc in preparation for generational mode changes
  • 419191c: 8325680: Uninitialised memory in deleteGSSCB of GSSLibStub.c:179
  • 349df0a: 8326726: Problem list Exhaustiveness.java due to 8326616
  • 552411f: 8326824: Test: remove redundant test in compiler/vectorapi/reshape/utils/TestCastMethods.java
  • 9f0e7da: 8326638: Crash in PhaseIdealLoop::remix_address_expressions due to unexpected Region instead of Loop
  • 81b065a: 8326714: Make file-local functions static in src/java.base/unix/native/libjava/childproc.c
  • 4fcae1a: 8326722: Cleanup unnecessary forward declaration in collectedHeap.hpp
  • c5c866a: 8326219: applications/kitchensink/Kitchensink8H.java timed out
  • ac3ce2a: 8326583: Remove over-generalized DefineNativeToolchain solution
  • ... and 64 more: https://git.openjdk.org/jdk/compare/33834b7d14de8cca1587d8405d13aec669b6cc23...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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 23, 2024
@MBaesken
Copy link
Member Author

Hi Christoph, thanks for the review !
Any other opinions/comments/reviews ?

@jaikiran
Copy link
Member

Hello Matthias, the proposal to improve that failure message looks OK to me. However, I feel that the newly proposed error message isn't too different than what it was earlier. Perhaps, we could do something like:

diff --git a/test/lib/jdk/test/lib/Asserts.java b/test/lib/jdk/test/lib/Asserts.java
index d503ea8e544..3b45d7f4129 100644
--- a/test/lib/jdk/test/lib/Asserts.java
+++ b/test/lib/jdk/test/lib/Asserts.java
@@ -199,10 +199,11 @@ public static void assertEquals(Object lhs, Object rhs) {
      */
     public static void assertEquals(Object lhs, Object rhs, String msg) {
         if ((lhs != rhs) && ((lhs == null) || !(lhs.equals(rhs)))) {
-            msg = Objects.toString(msg, "assertEquals")
-                    + ": expected " + Objects.toString(lhs)
-                    + " to equal " + Objects.toString(rhs);
-            fail(msg);
+            if (msg != null) {
+                fail(msg);
+            } else {
+                fail("assertEquals expected: " + lhs + " but was: " + rhs);
+            }
         }
     }

This is similar to what other test libraries usually report for such failures.

@RealCLanger
Copy link
Contributor

This is similar to what other test libraries usually report for such failures.

But in the case of a non-empty msg you would not see the actual values any more which I think could be helpful in a lot of cases...

@jaikiran
Copy link
Member

Hello Christoph, in that case the if block I proposed can be removed. Does the alternate proposed error message look better to you and Matthias?

@RealCLanger
Copy link
Contributor

Then maybe it should be

+            fail((msg == null ? "assertEquals" : msg) + " expected: " + lhs + " but was: " + rhs);

?

@jaikiran
Copy link
Member

Hello Christoph, yes that looks fine to me.

@dholmes-ora
Copy link
Member

Does "expected 0 to equal 1" really cause that much consternation? I just read it as "expected 0 to be equal to 1".

Aren't there existing test libraries that already "standardise" these kinds of utilities that we can emulate? testng? junit?

@jaikiran
Copy link
Member

Hello David, the updated text that I proposed to Matthias, of the form "expected: ... but was: ..." was borrowed from what junit5 reports for such assertion failures https://github.com/junit-team/junit5/blob/main/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertionFailureBuilder.java#L174

@MBaesken
Copy link
Member Author

Hello Christoph, yes that looks fine to me.

I adjusted it to the given suggestion.

Copy link
Member

@jaikiran jaikiran left a comment

Choose a reason for hiding this comment

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

Thank you Matthias. This looks good to me. I haven't checked references for this internal Asserts class. Before integrating, please run relevant tests that use this class just to be sure no test relies (and now fails) on the message being printed by the failing assertion.

@MBaesken
Copy link
Member Author

Thanks for the reviews !

/integrate

@openjdk
Copy link

openjdk bot commented Feb 28, 2024

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

  • 6cad07c: 8325746: Refactor Loop Unswitching code
  • 4dd6c44: 8326529: JFR: Test for CompilerCompile events fails due to time out
  • 33f2382: 8325807: Shenandoah: Refactor full gc in preparation for generational mode changes
  • 419191c: 8325680: Uninitialised memory in deleteGSSCB of GSSLibStub.c:179
  • 349df0a: 8326726: Problem list Exhaustiveness.java due to 8326616
  • 552411f: 8326824: Test: remove redundant test in compiler/vectorapi/reshape/utils/TestCastMethods.java
  • 9f0e7da: 8326638: Crash in PhaseIdealLoop::remix_address_expressions due to unexpected Region instead of Loop
  • 81b065a: 8326714: Make file-local functions static in src/java.base/unix/native/libjava/childproc.c
  • 4fcae1a: 8326722: Cleanup unnecessary forward declaration in collectedHeap.hpp
  • c5c866a: 8326219: applications/kitchensink/Kitchensink8H.java timed out
  • ... and 65 more: https://git.openjdk.org/jdk/compare/33834b7d14de8cca1587d8405d13aec669b6cc23...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 28, 2024

@MBaesken Pushed as commit 9b1f1e5.

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

@MBaesken
Copy link
Member Author

MBaesken commented Mar 1, 2024

Hello David, the updated text that I proposed to Matthias, of the form "expected: ... but was: ..." was borrowed from what junit5

Unfortunately we get now error messages like this

java.lang.RuntimeException: VM output should contain exactly one rtm locking statistics entry for method compiler.testlibrary.rtm.XAbortProvoker::forceAbort expected: 0 but was: 1

It should be ... expected: 1 but was: 0 ; the assertEquals has this interface assertEquals(Object lhs, Object rhs, String msg) so we have a left hand (lhs) and a right hand side (rhs) of a comparison but was is expected and what is what we got is not defined .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants