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

fix: fix flaky test #798

Merged
merged 1 commit into from May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -268,19 +269,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);
Thread t =
new Thread(
new Runnable() {
@Override
public void run() {
try {
threadStarted.set(true);
flowController.reserve(1, 0);
} catch (Exception e) {
}
}
});
t.start();
Thread.sleep(10);
// Wait 5 seconds for the thread to start, and 50 milliseconds after it's started to make sure
// 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);
}
Thread.sleep(50);
flowController.release(INITIAL_ELEMENT, 0);
t.join();
flowController.release(1, 0);
Expand Down