Skip to content

Commit d844053

Browse files
Stabilize flaky Maven instrumentation test (#5530)
1 parent d101167 commit d844053

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

dd-java-agent/instrumentation/maven-3.2.1/src/test/groovy/MavenTest.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import java.nio.file.Paths
1313

1414
class MavenTest extends CiVisibilityTest {
1515

16+
private static final int DEPENDENCIES_DOWNLOAD_RETRIES = 3
17+
1618
@TempDir
1719
Path projectFolder
1820

1921
@Override
2022
void setup() {
2123
givenMavenProjectFiles(specificationContext.currentIteration.name)
24+
givenMavenDependenciesAreLoaded()
25+
TEST_WRITER.clear() // loading dependencies will generate a test-session span
2226
}
2327

2428
@Override
@@ -255,6 +259,23 @@ class MavenTest extends CiVisibilityTest {
255259
FileUtils.copyDirectoryStructure(projectResourcesPath.toFile(), projectFolder.toFile())
256260
}
257261

262+
/**
263+
* Sometimes Maven has problems downloading project dependencies because of intermittent network issues.
264+
* Here, in order to reduce flakiness, we ensure that all of the dependencies are loaded (retrying if necessary),
265+
* before proceeding with running the build
266+
*/
267+
void givenMavenDependenciesAreLoaded() {
268+
String[] args = ["dependency:go-offline"]
269+
String workingDirectory = projectFolder.toString()
270+
for (int attempt = 0; attempt < DEPENDENCIES_DOWNLOAD_RETRIES; attempt++) {
271+
def exitCode = new MavenCli().doMain(args, workingDirectory, null, null)
272+
if (exitCode == 0) {
273+
return
274+
}
275+
}
276+
throw new AssertionError((Object) "Tried to download dependencies $DEPENDENCIES_DOWNLOAD_RETRIES times and failed")
277+
}
278+
258279
@Override
259280
String expectedOperationPrefix() {
260281
return "maven"

0 commit comments

Comments
 (0)