From 32c4ada25968a30fceab5da885c893debbe24cf7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 29 Aug 2019 19:04:00 +0200 Subject: Using test loop for browse service test --- .../services/MergeRepositoriesServiceTest.java | 53 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/MergeRepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/MergeRepositoriesServiceTest.java index 7497642ea..aaa601e3f 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/MergeRepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/MergeRepositoriesServiceTest.java @@ -46,6 +46,9 @@ public class MergeRepositoriesServiceTest private Path repoStage = getAppserverBase().resolve("data/repositories").resolve( "test-repository-stage" ); + private int maxChecks = 10; + private int checkWaitMs = 500; + @Test public void getMergeConflictedArtifacts() throws Exception @@ -56,12 +59,28 @@ public class MergeRepositoriesServiceTest waitForScanToComplete( TEST_REPOSITORY_STAGE ); - List artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY_STAGE, - TEST_REPOSITORY ); - - log.info( "conflicts: {}", artifactMetadatas ); + int checks = maxChecks; + Throwable ex = null; + while(checks-->0) { + try { + log.info("Test Try " + checks); + List artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY_STAGE, + TEST_REPOSITORY ); + log.info("conflicts: {}", artifactMetadatas); + + assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(8); + return; + } catch (Throwable e) { + ex = e; + } + Thread.currentThread().sleep(checkWaitMs); + } + if (ex!=null && ex instanceof AssertionError) { + throw (AssertionError)ex; + } else { + throw new Exception(ex); + } - assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 ); } @Test @@ -81,10 +100,28 @@ public class MergeRepositoriesServiceTest MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader ); - service.mergeRepositories( TEST_REPOSITORY_STAGE, TEST_REPOSITORY, true ); + int checks = maxChecks; + Throwable ex = null; + while(checks-->0) { + try { + log.info("Test Try " + checks); + service.mergeRepositories(TEST_REPOSITORY_STAGE, TEST_REPOSITORY, true); + + assertTrue(Files.exists(repo.resolve(mergedArtifactPath))); + assertTrue(Files.exists(repo.resolve(mergedArtifactPomPath))); + return; + } catch (Throwable e) { + log.info("Exception {}, {}", e.getMessage(), e.getClass()); + ex = e; + } + Thread.currentThread().sleep(checkWaitMs); + } + if (ex!=null && ex instanceof AssertionError) { + throw (AssertionError)ex; + } else if (ex!=null) { + throw new Exception(ex); + } - assertTrue( Files.exists(repo.resolve(mergedArtifactPath)) ); - assertTrue( Files.exists(repo.resolve(mergedArtifactPomPath)) ); } @After -- cgit v1.2.3