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

SlicedProgressMonitor: fix canceled() #428

Closed

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Dec 11, 2023

as soon as is started using sliced() cancel test fails because cancel is not forwarded:

org.eclipse.ltk.core.refactoring.tests.participants.CancelingParticipantTests

as soon as is started using sliced() cancel test fails because cancel is
not forwarded:

org.eclipse.ltk.core.refactoring.tests.participants.CancelingParticipantTests
@jukzi
Copy link
Contributor Author

jukzi commented Dec 11, 2023

see https://ci.eclipse.org/platform/job/eclipse.platform.ui/job/PR-1397/1/testReport/junit/AllTests%20org.eclipse.ltk.core.refactoring.tests.participants.ParticipantTests%20org.eclipse.ltk.core.refactoring.tests.participants/CancelingParticipantTests/testCreatePreChange/

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.eclipse.ltk.core.refactoring.tests.participants.CancelingParticipantTests.testCreatePreChange(CancelingParticipantTests.java:207)

@jukzi
Copy link
Contributor Author

jukzi commented Dec 11, 2023

@laeubi

@@ -86,6 +86,7 @@ public boolean isCanceled() {

@Override
public void setCanceled(boolean value) {
monitor.setCanceled(value);
Copy link
Member

@laeubi laeubi Dec 11, 2023

Choose a reason for hiding this comment

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

if you want this you need to synchronize on the monitor instance, beside that one usually don't want to cancel a slice, what is the use-case for that? According to the javadoc a monitor passed to a method should actually never call cancel so I'm not sure what these cancel tests "test"?

@laeubi
Copy link
Member

laeubi commented Dec 11, 2023

Just to give some context, slice() is to create an independent monitor in case of using each on different concurrent threads, so canceling should only cancel the current thread but not all threads.

You probably want to use SubMonitor.split(...) instead for the non-concurrent case (what cancels the parent as well).

@jukzi
Copy link
Contributor Author

jukzi commented Dec 11, 2023

You probably want to use SubMonitor.split(...) instead for the non-concurrent case (what cancels the parent as well).

I don't want to use SubMonitor.split(...) because it requires to construct a Submonitor instance before which does not refactor as easy. If split() works on multiple threads it should also work on single threads.

But ok: i see org.eclipse.core.runtime.IProgressMonitor.slice(int) javadoc indeed specified cancel() is not passed. How useless - at least for my usecase :-(

@jukzi jukzi closed this Dec 11, 2023
@laeubi
Copy link
Member

laeubi commented Dec 11, 2023

I don't want to use SubMonitor.split(...) because it requires to construct a Submonitor instance before which does not refactor as easy.

I must confess I don't understand you call SubMonitor.convert(IProgressMonitor) and then have it "constructed" so this is usually the very first call and then you can split it as you like.

If split() works on multiple threads it should also work on single threads.

Please read the docs, split() does not work on multiple threads, the returned monitor instance is suitable to be passed to other than the current thread, but you need to join later on, e.g on a parallel pipeline.

i see org.eclipse.core.runtime.IProgressMonitor.slice(int) javadoc indeed specified cancel() is not passed.

As explained, the cancel is to allow to cancel the one computation forked in a different thread, if you want to cancel all you need to call cancel on the monitor where you have started the split.

How useless - at least for my usecase :-(

For your usecase there is already SubMonitor.convert(IProgressMonitor) + split(...) what don't work for concurrent case as it split commits all previously splitted work ...

@jukzi
Copy link
Contributor Author

jukzi commented Dec 11, 2023

I must confess I don't understand you call SubMonitor.convert(IProgressMonitor) and then have it "constructed" so this is usually the very first call and then you can split it as you like.

if you do it on new code - ok. but we have hundrets of calls where i found no pattern convert all at once :-(

@laeubi
Copy link
Member

laeubi commented Dec 11, 2023

if you do it on new code - ok. but we have hundrets of calls where i found no pattern convert all at once :-(

I usually do the following:

  1. rename (with refactoring) the IProgressMonitor parameter of the method to "submonitor"
  2. now rename (without refactoring) the IProgressMonitor parameter of the method to "monitor"
  3. create a new local variable as SubMonitor submonitor = SubMonitor.convert(monitor)

maybe this can be automated with rewrite-maven-plugin one day...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants