Guarantee context listener removal
Put the listener removal in a finally block so it doesn't get skipped
when the future is cancelled/interrupted and throws an exception.
@@ -506,9 +506,11 @@ public final class TestWorkflowService extends WorkflowServiceGrpc.WorkflowServi
throws ExecutionException, InterruptedException {
final Context.CancellationListener canceler = context -> futureValue.cancel(true);
ctx.addListener(canceler, this.backgroundScheduler);
- final T result = futureValue.get();
+ try {
+ return futureValue.get();
+ } finally {
ctx.removeListener(canceler);
- return result;
+ }
}
@Override
