Skip to content

Commit 4a38a86

Browse files
committed
App could hang on status build failure #60
1 parent 3b09bf5 commit 4a38a86

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/main/java/org/scm4j/releaser/ExtendedStatusBuilder.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public ExtendedStatus getAndCachePatchStatus(String coords, CachedStatuses cache
5656
}
5757

5858
public ExtendedStatus getAndCacheStatus(Component comp, CachedStatuses cache, IProgress progress, boolean patch) {
59+
VCSRepository repo = null;
5960
try {
60-
VCSRepository repo = repoFactory.getVCSRepository(comp);
61+
repo = repoFactory.getVCSRepository(comp);
6162
ExtendedStatus existing = cache.putIfAbsent(repo.getUrl(), ExtendedStatus.DUMMY);
6263

6364
while (ExtendedStatus.DUMMY == existing) {
@@ -83,14 +84,17 @@ public ExtendedStatus getAndCacheStatus(Component comp, CachedStatuses cache, IP
8384
cache.replace(repo.getUrl(), res);
8485
return res;
8586
} catch (Exception e) {
87+
if (repo != null) {
88+
cache.remove(repo.getUrl());
89+
}
8690
if (e instanceof EReleaserException) {
8791
throw e;
8892
}
8993
throw new EBuildStatus(e, comp);
9094
}
9195
}
9296

93-
private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IProgress progress, VCSRepository repo, DelayedTag dt) {
97+
ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IProgress progress, VCSRepository repo, DelayedTag dt) {
9498
ReleaseBranchCurrent rb = reportDuration(() -> ReleaseBranchFactory.getCRB(repo), "CRB created", comp, progress);
9599
Boolean hasDelayedTag = dt != null && rb.getName().equals(Utils.getReleaseBranchName(repo, dt.getVersion()));
96100
LinkedHashMap<Component, ExtendedStatus> subComponents = new LinkedHashMap<>();
@@ -154,14 +158,7 @@ private ExtendedStatus getPatchStatus(Component comp, CachedStatuses cache, IPro
154158
}
155159

156160
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<>();
157-
Utils.async(rb.getMDeps(), (mdep) -> {
158-
try {
159-
recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, true);
160-
} catch (Exception e) {
161-
cache.remove(repo.getUrl());
162-
throw e;
163-
}
164-
});
161+
Utils.async(rb.getMDeps(), (mdep) -> recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, true));
165162
for (Component mdep : rb.getMDeps()) {
166163
subComponents.put(mdep, subComponentsLocal.get(mdep));
167164
}
@@ -254,7 +251,6 @@ private boolean areMDepsPatchesActualForPatch(Component rootComp, VCSRepository
254251

255252
// Any component `nextVersion`.truncatePatch is not equal to one mentioned in `mdeps` -> error (disallow minor upgrade/downgrade)
256253
if (!nextVersion.toReleaseNoPatch().equals(mDep.getVersion().toReleaseNoPatch())) {
257-
cache.remove(repo.getUrl());
258254
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextVersion.toPreviousPatch());
259255
}
260256

@@ -271,7 +267,6 @@ private boolean areMDepsPatchesActualForPatch(Component rootComp, VCSRepository
271267

272268
// Any component `nextVersion`.patch is less than one mentioned in `mdeps` -> error (patch upgrade only is allowed)
273269
if (nextVersionPatch < mDepPatch) {
274-
cache.remove(repo.getUrl());
275270
throw new EMinorUpgradeDowngrade(rootComp, mDep, verToActualizeOn);
276271
}
277272

@@ -337,13 +332,6 @@ private Boolean isNeedToFork(Component comp, ReleaseBranchCurrent rb, CachedStat
337332
}
338333

339334
private void recursiveGetAndCacheStatusAsync(ReleaseBranchCurrent rb, CachedStatuses cache, IProgress progress, VCSRepository repo, ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal) {
340-
Utils.async(rb.getMDeps(), (mdep) -> {
341-
try {
342-
recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, false);
343-
} catch (Exception e) {
344-
cache.remove(repo.getUrl());
345-
throw e;
346-
}
347-
});
335+
Utils.async(rb.getMDeps(), (mdep) -> recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, false));
348336
}
349337
}

src/test/java/org/scm4j/releaser/WorkflowBuildTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,20 @@ public void testShouldRemoveFromCacheOnErrorsIsNeedToFork() {
225225
verify(cache, atLeast(1)).remove(eq(repoUBL.getUrl()));
226226
}
227227
}
228+
229+
@Test
230+
public void testShouldRemoveFromCacheOnBuildStatusFailure() {
231+
ExtendedStatusBuilder esb = spy(new ExtendedStatusBuilder(repoFactory));
232+
CachedStatuses cache = spy(new CachedStatuses());
233+
RuntimeException testException = new RuntimeException("");
234+
ProgressConsole pc = new ProgressConsole();
235+
doThrow(testException).when(esb).getMinorStatus(compUnTillDb, cache, pc, repoUnTillDb, null);
236+
237+
try {
238+
esb.getAndCacheStatus(compUBL, cache, pc, false);
239+
fail();
240+
} catch (RuntimeException e) {
241+
verify(cache, atLeast(1)).remove(eq(repoUnTillDb.getUrl()));
242+
}
243+
}
228244
}

0 commit comments

Comments
 (0)