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

Show progress when searching test methods in JUnit run configuration #653 #675

Conversation

fedejeanne
Copy link
Contributor

@fedejeanne fedejeanne commented Jul 20, 2023

What it does

Move the logic to search for test methods from JUnitLaunchConfigurationTab to TestSearchEngine::findTestMethods. Extract the whole logic for caching the results into TestMethodsCache (new class) and do the whole searching and caching more efficiently i.e. only when necessary and showing the progress with a monitor by using ModalContext::run

Fixes #683
Contributes to #653

This PR shows a progress indicator when searching for test methods in a class (which may happen when one opens a JUnit run configuration). The progress indicator looks like this when you first open the Run configurations and a JUnit configuration is selected:

image

... and like this when you select or edit an existing JUnit run configuration and force a new search for test methods (the progress indicator appears at the bottom of the Run configurations dialog).

image

How to test

The main goal is to open some Run configurations for JUnit tests and move between them, letting them search the necessary test methods.

All of the following must hold true while testing:

  • If the UI is blocked (which is normal) then some progress report should appear, either in a separate dialog (when opening the Run configurations for the first time) or in a progress bar at the bottom of the Run configurations dialog.
  • Previous results from the same run configuration (project + class + JUnit runner) should be cached e.g. if you already found all test methods for class A in project B and for JUnit5 then changing to class A2 might trigger a search (if A2 exists) but setting the class back to A should not trigger another search.
  • Selecting another configuration in the dialog (on the left-side panel) empties the cache.
  • If you cancel a search then the Test method (text field) and its Search button should be deactivated since the methods of the class are not known.
    image
  • It follows that if you cancel a search then the configuration is invalid i.e. the Run button should be deactivated and an error should be displayed in the notification area of the dialog (upper area).

A small hack to help testing

If you need more time to see the progress dialog/bar then you can modify TestSearchEngine::collectMethodNames like this:

	private static void collectMethodNames(IType type, IJavaProject javaProject, String testKindId, Set<String> methodNames, IProgressMonitor monitor) throws JavaModelException {
		if (type == null) {
			return;
		}

		SubMonitor subMonitor= SubMonitor.convert(monitor, 3 + 3); // Add +3

		// Add this idle wait of 3 seconds and advance the progress in the subMonitor
		for (int i= 0; i < 3; i++) {
			try {
				Thread.sleep(1_000);
				subMonitor.split(1);
			} catch (InterruptedException e) {
				// ignore
			}
		}

		// leave the rest unchanged
                ...
	}

How did I test?

These are all the stuff I did and tried when testing:

  • I created a hierarchy of 2 test classes so that I may run tests in the super-class from the sub-class
  • I added test methods both in the super-class and in the sub-class
  • I created Run configurations for the test methods and also for the complete classes (i.e. left the Test method empty in the configuration dialog).
  • I created a completely empty run configuration which will never be able to run but it helps to empty the cache without closing the Run configurations dialog (selecting it empties the cache of the previous JUnit run configuration).
  • I edited the existing JUnit configuration in every possible way I could imagine, entering both valid and invalid values for the project, test class and test method and also switching between JUnit3, 4 and 5 in the drop-down menu ("Test runner")
  • I also used the Browse... and Search buttons to change the project and the class in the run configuration
  • I sometimes canceled the search for test methods
  • I changed the project / test class / test runner back and forth several times (without selecting another Run configuration from the left-side panel) and purposely triggered new searches for test methods.
  • I completely emptied the cache by selecting another (an empty) run configuration in the left-side panel --> no searches should occur if the configuration is empty

Author checklist

@fedejeanne fedejeanne force-pushed the bugs/653-search-test-methods-cancellable branch from 4ade735 to d98100b Compare July 20, 2023 05:32
@fedejeanne
Copy link
Contributor Author

Random test failure of SaveParticipantTest.testFormatChangeBug561164 already documented in #79

@fedejeanne fedejeanne force-pushed the bugs/653-search-test-methods-cancellable branch 2 times, most recently from 5820765 to 7ed50be Compare July 26, 2023 14:01
@fedejeanne fedejeanne force-pushed the bugs/653-search-test-methods-cancellable branch from 7ed50be to 00c49ff Compare August 8, 2023 08:39
@fedejeanne
Copy link
Contributor Author

Hello all,
there's been no activity on this one in the past few weeks.
Please let me know if there's anything I can do to help reviewing this PR (more details/screenshots/comments).

I just rebased and solved the conflicts to ease the review.

@jjohnstn jjohnstn self-requested a review August 10, 2023 01:38
@jjohnstn
Copy link
Contributor

@fedejeanne Will take a look

Copy link
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

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

Tried it out. Works well, but have the following comment.

I used your delay code to be able to cancel a search. When a search is cancelled, it would be helpful if the error message states that it cannot find method after cancelled search. After cancelling, I believe the search button for method should remain active and if pressed, should restart the search. Otherwise, after cancelling a search a user has no options other than to close without saving. I had a case where it was running all tests and after cancelling it left the Run button active because it did not have to do the verification which is fine.

@fedejeanne fedejeanne force-pushed the bugs/653-search-test-methods-cancellable branch 2 times, most recently from 51bcb12 to b0ac9ea Compare August 11, 2023 10:53
@fedejeanne
Copy link
Contributor Author

Thank you for reviewing and testing!

I added a hint that says the user canceled the operation in order to let the user know why can't the method be found.
Additionally, the Search... button now remains active even after cancellation and triggers the search again if necessary.

image

@jjohnstn
Copy link
Contributor

jjohnstn commented Aug 11, 2023

Hi @fedejeanne Thanks for the changes. Could you take a look at the test failures? Monday is cut-off for M3 so if we can't get this in by then, it will have to wait until 4.30 M1.

@jjohnstn
Copy link
Contributor

There was a fix recently in jdt.ui for Junit 4/5 failures. Please rebase on master (don't merge) and do a force push if needed.

…e-jdt#653

Move the logic to search for test methods from
`JUnitLaunchConfigurationTab` to `TestSearchEngine::findTestMethods`.
Extract the whole logic for caching the results into `TestMethodsCache`
(new class) and do the whole searching and caching more efficiently i.e.
only when necessary and showing the progress with a monitor by using
`ModalContext::run`

Fixes eclipse-jdt#683
Contributes to eclipse-jdt#653
@jjohnstn jjohnstn force-pushed the bugs/653-search-test-methods-cancellable branch from b0ac9ea to 169cc10 Compare August 11, 2023 21:08
@jjohnstn
Copy link
Contributor

I made the rebase for you. I had a similar problem with a PR and rebasing fixed the test failures.

@jjohnstn jjohnstn merged commit a873aaf into eclipse-jdt:master Aug 12, 2023
@jjohnstn jjohnstn self-assigned this Aug 12, 2023
@jjohnstn jjohnstn added enhancement New feature or request noteworthy Noteworthy feature labels Aug 12, 2023
@jjohnstn jjohnstn added this to the 4.29 M3 milestone Aug 12, 2023
@jjohnstn
Copy link
Contributor

Thanks @fedejeanne I made a couple tweaks (no logging interrupt exception and fixing error message to not spit out null when the testmethods field not filled in). Merged for M3.

@fedejeanne
Copy link
Contributor Author

Thank you very much for the review, changes and merging @jjohnstn ! And I'm glad to see that it's a noteworthy change!

@fedejeanne fedejeanne deleted the bugs/653-search-test-methods-cancellable branch August 14, 2023 06:54
@jjohnstn
Copy link
Contributor

@fedejeanne With regards to noteworthy, would you like to create a N&N PR for this in eclipse-platform/www.eclipse.org-eclipse.git if you haven't already? If you're not sure, I can do it for you.

@fedejeanne
Copy link
Contributor Author

... would you like to create a N&N PR...?

My pleasure!

@fedejeanne
Copy link
Contributor Author

fedejeanne added a commit to fedejeanne/eclipse.jdt.ui that referenced this pull request Aug 23, 2023
…clipse-jdt#653 (eclipse-jdt#675)

* Show progress when searching test methods in run configuration eclipse-jdt#653

Move the logic to search for test methods from
`JUnitLaunchConfigurationTab` to `TestSearchEngine::findTestMethods`.
Extract the whole logic for caching the results into `TestMethodsCache`
(new class) and do the whole searching and caching more efficiently i.e.
only when necessary and showing the progress with a monitor by using
`ModalContext::run`

Fixes eclipse-jdt#683
Contributes to eclipse-jdt#653

Co-authored-by: Jeff Johnston <[email protected]>
fedejeanne added a commit to fedejeanne/eclipse.jdt.ui that referenced this pull request Aug 23, 2023
…clipse-jdt#653 (eclipse-jdt#675)

* Show progress when searching test methods in run configuration eclipse-jdt#653

Move the logic to search for test methods from
`JUnitLaunchConfigurationTab` to `TestSearchEngine::findTestMethods`.
Extract the whole logic for caching the results into `TestMethodsCache`
(new class) and do the whole searching and caching more efficiently i.e.
only when necessary and showing the progress with a monitor by using
`ModalContext::run`

Fixes eclipse-jdt#683
Contributes to eclipse-jdt#653

Co-authored-by: Jeff Johnston <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request noteworthy Noteworthy feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Run configurations... dialog] Opening a JUnit configuration takes too long (UI freeze)
2 participants