#12268 reset _iterate flag when another processing is scheduled
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
5105afafa4
commit
2018c439b6
|
@ -295,6 +295,7 @@ public abstract class IteratingCallback implements Callback
|
||||||
}
|
}
|
||||||
case SCHEDULED:
|
case SCHEDULED:
|
||||||
{
|
{
|
||||||
|
_iterate = false;
|
||||||
// we won the race against the callback, so the callback has to process and we can break processing
|
// we won the race against the callback, so the callback has to process and we can break processing
|
||||||
_state = State.PENDING;
|
_state = State.PENDING;
|
||||||
break processing;
|
break processing;
|
||||||
|
@ -321,6 +322,7 @@ public abstract class IteratingCallback implements Callback
|
||||||
callOnSuccess = true;
|
callOnSuccess = true;
|
||||||
if (action != Action.SCHEDULED)
|
if (action != Action.SCHEDULED)
|
||||||
throw new IllegalStateException(String.format("%s[action=%s]", this, action));
|
throw new IllegalStateException(String.format("%s[action=%s]", this, action));
|
||||||
|
_iterate = false;
|
||||||
// we lost the race, so we have to keep processing
|
// we lost the race, so we have to keep processing
|
||||||
_state = State.PROCESSING;
|
_state = State.PROCESSING;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -22,7 +22,11 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
@ -45,6 +49,37 @@ public class IteratingCallbackTest
|
||||||
scheduler.stop();
|
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
|
@Test
|
||||||
public void testNonWaitingProcess() throws Exception
|
public void testNonWaitingProcess() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue