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: flaky deadlock in test updateTokenValueBeforeWake #1091

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -46,12 +46,9 @@
import com.google.auth.TestUtils;
import com.google.auth.http.AuthHttpConstants;
import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory;
import com.google.auth.oauth2.OAuth2Credentials.OAuthValue;
import com.google.auth.oauth2.OAuth2Credentials.RefreshTask;
import com.google.auth.oauth2.OAuth2Credentials.RefreshTaskListener;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ListenableFutureTask;
import com.google.common.util.concurrent.SettableFuture;
import java.io.IOException;
import java.net.URI;
Expand All @@ -60,7 +57,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -882,15 +878,6 @@ public void updateTokenValueBeforeWake() throws IOException, InterruptedExceptio
AccessToken refreshedToken = new AccessToken("2/MkSJoj1xsli0AccessToken_NKPY2", null);
refreshedTokenFuture.set(refreshedToken);

final ListenableFutureTask<OAuthValue> task =
ListenableFutureTask.create(
new Callable<OAuthValue>() {
@Override
public OAuthValue call() throws Exception {
return OAuthValue.create(refreshedToken, new HashMap<>());
}
});

OAuth2Credentials creds =
new OAuth2Credentials() {
@Override
Expand All @@ -901,22 +888,6 @@ public AccessToken refreshAccessToken() {
// in order to wait for the refresh to complete.
this.notify();
}
RefreshTaskListener listener =
new RefreshTaskListener(task) {
@Override
public void run() {
try {
// Sleep before setting accessToken to new accessToken. Refresh should not
// complete before this, and the accessToken is `null` until it is.
Thread.sleep(300);
super.run();
} catch (Exception e) {
fail("Unexpected error. Exception: " + e);
}
}
};

this.refreshTask = new RefreshTask(task, listener);

try {
// Sleep for 100 milliseconds to give parent thread time to create a refresh future.
Expand All @@ -934,6 +905,9 @@ public void run() {
@Override
public void run() {
try {
// Sleep for 100 milliseconds to give parent thread time to grab a lock on the
// creds object.
Thread.sleep(100);
creds.refresh();
assertNotNull(creds.getAccessToken());
} catch (Exception e) {
Expand Down