Skip to content

Commit

Permalink
Fix #9476 IteratingCallback multiple onCompleteFailure calls (#9935)
Browse files Browse the repository at this point in the history
Change state to FAILED from PENDING state
  • Loading branch information
gregw authored Jun 21, 2023
1 parent ec7e1fd commit d935651
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public void failed(Throwable x)
break;
case PENDING:
{
_state = State.FAILED;
failure = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import org.eclipse.jetty.util.thread.Scheduler;
Expand Down Expand Up @@ -327,4 +328,44 @@ boolean waitForComplete() throws InterruptedException
return isSucceeded();
}
}

@Test
public void testMultipleFailures() throws Exception
{
AtomicInteger process = new AtomicInteger();
AtomicInteger failure = new AtomicInteger();
IteratingCallback icb = new IteratingCallback()
{
@Override
protected Action process() throws Throwable
{
process.incrementAndGet();
return Action.SCHEDULED;
}

@Override
protected void onCompleteFailure(Throwable cause)
{
super.onCompleteFailure(cause);
failure.incrementAndGet();
}
};

icb.iterate();
assertEquals(1, process.get());
assertEquals(0, failure.get());

icb.failed(new Throwable("test1"));

assertEquals(1, process.get());
assertEquals(1, failure.get());

icb.succeeded();
assertEquals(1, process.get());
assertEquals(1, failure.get());

icb.failed(new Throwable("test2"));
assertEquals(1, process.get());
assertEquals(1, failure.get());
}
}

0 comments on commit d935651

Please sign in to comment.