Skip to content

Commit 30d58f2

Browse files
chore: fix appengine.libraries unit test (#3747)
* chore: fix appengine.libraries unit test * add logger ID for concurrency debugging * add inter-file-change grace period to prevent flakiness * explain what the logger uuid is for
1 parent dfd3a10 commit 30d58f2

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

plugins/com.google.cloud.tools.eclipse.appengine.libraries.test/src/com/google/cloud/tools/eclipse/appengine/libraries/model/CloudLibrariesInPluginXmlTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void testObjectifyLibraryConfig() throws URISyntaxException {
168168
assertThat(objectifyMavenCoordinates.getArtifactId(), is("objectify"));
169169
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(
170170
objectifyMavenCoordinates.getVersion());
171-
assertEquals(new DefaultArtifactVersion("6.0.9"), artifactVersion);
171+
assertEquals(new DefaultArtifactVersion("6.1.1"), artifactVersion);
172172
assertThat(objectifyMavenCoordinates.getType(), is("jar"));
173173
assertNull(objectifyMavenCoordinates.getClassifier());
174174

@@ -184,7 +184,7 @@ public void testObjectifyLibraryConfig() throws URISyntaxException {
184184
assertThat(guavaMavenCoordinates.getRepository(), is("central"));
185185
assertThat(guavaMavenCoordinates.getGroupId(), is("com.google.guava"));
186186
assertThat(guavaMavenCoordinates.getArtifactId(), is("guava"));
187-
assertThat(guavaMavenCoordinates.getVersion(), is("31.1-jre"));
187+
assertThat(guavaMavenCoordinates.getVersion(), is("32.1.2-jre"));
188188
assertThat(guavaMavenCoordinates.getType(), is("jar"));
189189
assertNull(guavaMavenCoordinates.getClassifier());
190190

@@ -242,7 +242,7 @@ public void testObjectify6LibraryConfig() throws URISyntaxException {
242242
assertThat(guavaMavenCoordinates.getRepository(), is("central"));
243243
assertThat(guavaMavenCoordinates.getGroupId(), is("com.google.guava"));
244244
assertThat(guavaMavenCoordinates.getArtifactId(), is("guava"));
245-
assertThat(guavaMavenCoordinates.getVersion(), is("31.1-jre"));
245+
assertThat(guavaMavenCoordinates.getVersion(), is("32.1.2-jre"));
246246
assertThat(guavaMavenCoordinates.getType(), is("jar"));
247247
assertNull(guavaMavenCoordinates.getClassifier());
248248

plugins/com.google.cloud.tools.eclipse.googleapis.test/src/com/google/cloud/tools/eclipse/googleapis/internal/DefaultAccountProviderTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.Optional;
3333
import java.util.logging.Logger;
3434
import java.util.stream.Collectors;
35+
import java.util.UUID;
36+
import org.junit.After;
3537
import org.junit.Before;
3638
import org.junit.Rule;
3739
import org.junit.Test;
@@ -58,13 +60,18 @@ public class DefaultAccountProviderTest {
5860
private Runnable listenerFunction;
5961

6062
static final String TEMP_ADC_FILENAME = "test_adc.json";
61-
private final Logger LOGGER = Logger.getLogger(this.getClass().getName());
63+
private Logger LOGGER;
64+
private static final long FILE_CHANGE_WAIT_MS = 500;
6265

6366
@Rule
6467
public TemporaryFolder tempFolder = new TemporaryFolder();
6568

6669
@Before
67-
public void setup() throws IOException {
70+
public void setup() throws IOException, InterruptedException {
71+
// we add a small ID to the logger statements to distinguish among test cases
72+
String uuid = UUID.randomUUID().toString();
73+
String uuidShort = uuid.substring(uuid.lastIndexOf('-'));
74+
LOGGER = Logger.getLogger(this.getClass().getName() + uuidShort);
6875
LOGGER.info("setup()");
6976
LOGGER.info("Temp folder location: " + tempFolder.getRoot().toPath().toString());
7077
provider = new TestDefaultAccountProvider(tempFolder.newFile(TEMP_ADC_FILENAME).toPath(), tempFolder);
@@ -78,6 +85,11 @@ public void setup() throws IOException {
7885
provider.addCredentialChangeListener(listenerFunction);
7986
}
8087

88+
@After
89+
public void tearDown() {
90+
LOGGER.info("Test finished");
91+
}
92+
8193
@Test
8294
public void testFileWriteTriggersListeners() throws InterruptedException {
8395
login(TOKEN_1);
@@ -102,7 +114,7 @@ public void testFileWriteTriggersListeners() throws InterruptedException {
102114
}
103115

104116
@Test
105-
public void testFileWriteChangesReturnedAccount() {
117+
public void testFileWriteChangesReturnedAccount() throws InterruptedException {
106118
Optional<Account> acct = provider.getAccount();
107119
assertFalse(acct.isPresent());
108120

@@ -127,7 +139,7 @@ public void testFileWriteChangesReturnedAccount() {
127139
}
128140

129141
@Test
130-
public void testFileWriteChangesReturnedCredential() {
142+
public void testFileWriteChangesReturnedCredential() throws InterruptedException {
131143
Optional<Credential> cred = provider.getCredential();
132144
assertFalse(cred.isPresent());
133145

@@ -156,7 +168,7 @@ private Path getTempAdcPath() {
156168
return result;
157169
}
158170

159-
private void login(String token) {
171+
private void login(String token) throws InterruptedException {
160172
LOGGER.info("login(" + token + ")");
161173
try {
162174
File adcFile = getTempAdcPath().toFile();
@@ -175,17 +187,19 @@ private void login(String token) {
175187
LOGGER.info(
176188
"login() post-write contents: " + Files.readAllLines(adcFile.toPath())
177189
.stream().collect(Collectors.joining()));
190+
Thread.sleep(FILE_CHANGE_WAIT_MS);
178191
} catch (IOException ex) {
179192
fail(ex.getMessage());
180193
}
181194
}
182195

183-
private void logout() {
196+
private void logout() throws InterruptedException {
184197
LOGGER.info("logout()");
185198
File adcFile = getTempAdcPath().toFile();
186199
if (adcFile.exists()) {
187200
LOGGER.info("logout() delete file");
188201
adcFile.delete();
202+
Thread.sleep(FILE_CHANGE_WAIT_MS);
189203
}
190204
}
191205

0 commit comments

Comments
 (0)