Skip to content

12.0.x: IteratingCallback reset _iterate flag when another processing is scheduled #12269

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

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private void processing()
}
case SCHEDULED:
{
_iterate = false;
// we won the race against the callback, so the callback has to process and we can break processing
_state = State.PENDING;
break processing;
Expand All @@ -321,6 +322,7 @@ private void processing()
callOnSuccess = true;
if (action != Action.SCHEDULED)
throw new IllegalStateException(String.format("%s[action=%s]", this, action));
_iterate = false;
// we lost the race, so we have to keep processing
_state = State.PROCESSING;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -45,6 +49,37 @@ public void dispose() throws Exception
scheduler.stop();
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testIterateWhileProcessingLoopCount(boolean succeededWinsRace)
{
var icb = new IteratingCallback()
{
int counter = 0;

@Override
protected Action process()
{
int counter = this.counter++;
if (counter == 0)
{
iterate();
if (succeededWinsRace)
succeeded();
else
scheduler.schedule(this::succeeded, 100, TimeUnit.MILLISECONDS);
return Action.SCHEDULED;
}
return Action.IDLE;
}
};

icb.iterate();

await().atMost(5, TimeUnit.SECONDS).until(icb::isIdle, is(true));
assertEquals(2, icb.counter);
}

@Test
public void testNonWaitingProcess() throws Exception
{
Expand Down
Loading