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

Fix Issue 390: Better generation process monitor #393

Conversation

pderakhshanfar
Copy link
Collaborator

Description of changes made

This PR fixes #390 issue and provides a better process monitoring procedure

Why is merge request needed

Fixes #390

What is missing?

We need a major refactoring by removing controller totally and using indicator instead to track the status of test generation processes

  • I have checked that I am merging into correct branch

Copy link
Collaborator

@Vladislav0Art Vladislav0Art left a comment

Choose a reason for hiding this comment

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

I left some suggestions about small code parts.

Generally, my main concern is using CustomProgressIndicator even further in the plugin's control flow.

@@ -11,4 +11,5 @@ interface CustomProgressIndicator {
fun isCanceled(): Boolean
fun start()
fun stop()
fun isRunning(): Boolean
Copy link
Collaborator

@Vladislav0Art Vladislav0Art Oct 15, 2024

Choose a reason for hiding this comment

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

Note: It'll require publishing a new core version since the interface changes.
CC: @pderakhshanfar

Comment on lines +49 to +51
if (indicator != null &&
indicator!!.isRunning()
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the expression is quite short, so making it as this is fine:

if ((indicator != null) && indicator!!.isRunning()) {

@@ -26,6 +27,7 @@ class TestGenerationController {
private fun showGenerationRunningNotification(project: Project) {
val terminateButton: AnAction = object : AnAction("Terminate") {
override fun actionPerformed(e: AnActionEvent) {
indicator?.stop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Only my thoughts below; no request to any action]:

I genuinely do not like that we bring a dependency on CustomProgressIndicator further in the control flow.

Valich suggested us to transition to coroutines and reduce our CustomProgressIndicator interface to a viewer of the indicator's text (i.e. it should merely allow setting the indicator's display text).

Note: Calling stop method on the IntelliJ's ProgressIndicator is usually discouraged, as I saw in its Javadoc.

I suggest a major refactoring somewhere in the future after the release to tackle this long-lasting issue with CustomProgressIndicator. There was an issue somewhere in this regard.

CC: @pderakhshanfar @Hello-zoka @arksap2002.

Comment on lines +62 to +67
// If indicator is null, we have never initiated an indicator before and there is no running test generation
if (indicator == null) {
return false
}

if (indicator!!.isRunning()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about:

fun isGeneratorRunning(project: Project): Boolean {
  // If indicator is null, we have never initiated an indicator before and there is no running test generation
  return indicator?.let { it.isRunning() } ?: false;
}

// OR:

fun isGeneratorRunning(project: Project): Boolean = indicator?. let { it.isRunning() } ?: false;

Comment on lines +98 to +100
try {
toolWindow?.hide()
} catch (_: AlreadyDisposedException) {} // Make sure the process continues if the tool window is already closed
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to log the error at least; silencing it potentially may bring problems in the future.

generatedTestsTabData.contentManager?.removeContent(generatedTestsTabData.content!!, true)
ToolWindowManager.getInstance(project).getToolWindow("TestSpark")?.hide()
coverageVisualisationTabBuilder.closeToolWindowTab()
} catch (_: AlreadyDisposedException) {} // Make sure the process continues if the tool window is already closed
Copy link
Collaborator

Choose a reason for hiding this comment

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

logging

Comment on lines 28 to +30
val terminateButton: AnAction = object : AnAction("Terminate") {
override fun actionPerformed(e: AnActionEvent) {
indicator?.stop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to close this popup modal after a user clicks "Terminate." Otherwise, I can click as many times as I like (it does not cause errors, though).

@pderakhshanfar pderakhshanfar merged commit 67ba61d into development Oct 15, 2024
3 checks passed
@arksap2002 arksap2002 deleted the pderakhshanfar/bug-fix/390-better-generation-process-monitor branch October 15, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Ready for review PR redy for review Urgent Urgant PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Generation is already running" warning when a different project opened
2 participants