Skip to content

Commit aa47852

Browse files
authored
fix the result size in ParallelResult (#339)
* fix the result size in ParallelResult * fix test cases for nesting mode
1 parent cfb10a5 commit aa47852

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

sdk-integration-tests/src/test/java/software/amazon/lambda/durable/ParallelIntegrationTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,17 +1142,21 @@ void testParallelWithFirstSuccessful_earlyTermination(NestingType nestingType, i
11421142
var result = parallel.get();
11431143
assertEquals(ConcurrencyCompletionStatus.MIN_SUCCESSFUL_REACHED, result.completionStatus());
11441144
assertTrue(result.completionStatus().isSucceeded());
1145-
// todo: the result is constructed when handling parallel completion,
1146-
// which might be earlier than the last branch is added.
1147-
assertTrue(result.size() <= 3);
1148-
assertTrue(result.succeeded() <= result.size());
1145+
assertEquals(3, result.size());
1146+
assertTrue(result.succeeded() <= 3);
11491147
assertTrue(1 <= result.succeeded());
11501148

11511149
return "done";
11521150
});
11531151

11541152
var result = runner.runUntilComplete("test");
11551153
assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
1156-
assertEquals(events, result.getHistoryEvents().size());
1154+
if (nestingType == NestingType.FLAT) {
1155+
assertEquals(2, result.getHistoryEvents().size());
1156+
} else {
1157+
// might 4 if only 1 branch completed and at most 8 if all branches completed
1158+
assertTrue(4 <= result.getHistoryEvents().size());
1159+
assertTrue(result.getHistoryEvents().size() <= events);
1160+
}
11571161
}
11581162
}

sdk/src/main/java/software/amazon/lambda/durable/operation/ParallelOperation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ protected void replay(Operation existing) {
127127
@Override
128128
public ParallelResult get() {
129129
join();
130-
return cachedResult;
130+
return new ParallelResult(
131+
getBranches().size(), // size might be updated after cached result is built
132+
cachedResult.succeeded(),
133+
cachedResult.failed(),
134+
cachedResult.completionStatus());
131135
}
132136

133137
/** Calls {@link #get()} if not already called. Guarantees that the context is closed. */

0 commit comments

Comments
 (0)