Skip to content
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

test: deflake flow control test #2259

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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 @@ -36,9 +36,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -264,6 +264,10 @@ public ApiFuture<List<MutateRowsResponse>> futureCall(
try {
Thread.sleep(Integer.valueOf(latencyHeader.get(0)));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return ApiFutures.immediateFailedFuture(
new IllegalStateException(
"Interrupted while sleeping as requested: " + latencyHeader, e));
}
if (Integer.valueOf(latencyHeader.get(0)) == DEADLINE_EXCEEDED_LATENCY) {
return ApiFutures.immediateFailedFuture(
Expand All @@ -277,32 +281,30 @@ public ApiFuture<List<MutateRowsResponse>> futureCall(

private void createFlowControlEvent(final FlowController flowController) throws Exception {
flowController.reserve(INITIAL_ELEMENT, 0);
final AtomicBoolean threadStarted = new AtomicBoolean(false);
CompletableFuture<Void> threadStarted = new CompletableFuture<>();
CompletableFuture<Void> threadReservedOne = new CompletableFuture<>();
Thread t =
new Thread(
new Runnable() {
@Override
public void run() {
threadStarted.complete(null);
try {
threadStarted.set(true);
flowController.reserve(1, 0);
threadReservedOne.complete(null);
} catch (Exception e) {
threadReservedOne.completeExceptionally(e);
}
}
});
t.start();
// Wait 5 seconds for the thread to start, and 50 milliseconds after it's started to make sure
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
// flowController.reserve(1, 0) is blocked and creates a throttling event. It should never take
// so long.
for (int i = 0; i < 1000; i++) {
if (threadStarted.get()) {
break;
}
Thread.sleep(5);
}
threadStarted.get();
Thread.sleep(50);
flowController.release(INITIAL_ELEMENT, 0);
t.join();
threadReservedOne.get();
flowController.release(1, 0);

assertThat(flowController.getFlowControlEventStats().getLastFlowControlEvent()).isNotNull();
Expand Down
Loading