Skip to content

Commit

Permalink
address comments by @ikhoon
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Aug 1, 2024
1 parent 7289baf commit 06012a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ default void finishNow() {

enum State {
INIT,
PENDING,
SCHEDULED,
FINISHED,
}

/**
* A cancellation task invoked by the scheduler when its timeout exceeds or invoke by the user.
*/
@FunctionalInterface
interface CancellationTask {
/**
* Returns {@code true} if the cancellation task can be scheduled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public void start() {
if (state != State.INIT) {
return;
}
state = State.PENDING;
state = State.SCHEDULED;
startTimeNanos = ticker.read();
if (timeoutMode == TimeoutMode.SET_FROM_NOW) {
final long elapsedTimeNanos = startTimeNanos - setFromNowStartNanos;
timeoutNanos = LongMath.saturatedSubtract(timeoutNanos, elapsedTimeNanos);
timeoutNanos = Long.max(LongMath.saturatedSubtract(timeoutNanos, elapsedTimeNanos), 0);
}
if (timeoutNanos != Long.MAX_VALUE) {
scheduledFuture = eventLoop().schedule(() -> invokeTask(null), timeoutNanos, NANOSECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ void shouldRunHooksWhenContextIsPushed() {
hookEvents.clear();
response = client.get("http://foo.com:" + server.httpPort() + "/virtualhost");
assertThat(response.status()).isEqualTo(HttpStatus.OK);
// we don't do containsExactly here because there is no easy way to guarantee that
// all context hooks from the previous request have been completed
assertThat(hookEvents).contains(
assertThat(hookEvents).containsExactly(
"ClientBuilder/push",
"ClientContext/push",
"ServerBuilder/push",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void cancelTimeoutAfterDeadline() {
void cancelTimeoutBySettingTimeoutZero() {
executeInEventLoop(1000, scheduler -> {
scheduler.setTimeoutNanos(SET_FROM_START, Long.MAX_VALUE);
assertThat(scheduler.state()).isEqualTo(State.PENDING);
assertThat(scheduler.state()).isEqualTo(State.SCHEDULED);
});
}

Expand Down Expand Up @@ -272,7 +272,7 @@ public void run(Throwable cause) {
assertThat(scheduler.isFinished()).isFalse();

scheduler.setTimeoutNanos(SET_FROM_NOW, MILLISECONDS.toNanos(1000));
assertThat(scheduler.state()).isEqualTo(State.PENDING);
assertThat(scheduler.state()).isEqualTo(State.SCHEDULED);

schedulerRef.set(scheduler);
whenTimedOutRef.set(scheduler.whenCancelled());
Expand Down Expand Up @@ -339,7 +339,7 @@ public void run(Throwable cause) {
assertThat(scheduler.isFinished()).isFalse();

scheduler.setTimeoutNanos(SET_FROM_NOW, MILLISECONDS.toNanos(1000));
assertThat(scheduler.state()).isEqualTo(State.PENDING);
assertThat(scheduler.state()).isEqualTo(State.SCHEDULED);

schedulerRef.set(scheduler);
whenCancellingRef.set(scheduler.whenCancelling());
Expand Down

0 comments on commit 06012a1

Please sign in to comment.