mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
test(lambda): wait for each SQS poll before advancing the batching-window clock (#4796)
batchingWindowHoldsUnderfilledBatchUntilTheWindowElapses slept 25ms between polls and then moved the fake clock forward. The poll runs on a separate thread and starts the window when it reads the clock, so a poll that took longer than 25ms on a busy runner started the window late (for example at 3s). The later polls were skipped while it was still running, and at 5s the window had not elapsed, so the function was never invoked. pollAndInvoke now returns the future of the submitted poll, and the test waits for each poll to finish before moving the clock.
This commit is contained in:
1 parent
419e840260
commit
95b5acb1db
2 files changed
+27
-7
No files matched your search
@@ -26,9 +26,11 @@ import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.LongSupplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -152,15 +154,18 @@ public class SqsEventSourcePoller implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
/** Package-private (not private) only so unit tests can drive a single poll directly. */
|
||||
void pollAndInvoke(EventSourceMapping esm) {
|
||||
/**
|
||||
* Package-private (not private) only so unit tests can drive a single poll directly and wait
|
||||
* for it to finish through the returned future.
|
||||
*/
|
||||
Future<?> pollAndInvoke(EventSourceMapping esm) {
|
||||
// Skip this tick if a previous poll for this ESM is still in progress.
|
||||
// This prevents concurrent deliveries of the same message when the Lambda
|
||||
// cold-start / execution time exceeds the SQS visibility timeout.
|
||||
if (activePolls.putIfAbsent(esm.getUuid(), Boolean.TRUE) != null) {
|
||||
return;
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
pollExecutor.submit(() -> {
|
||||
return pollExecutor.submit(() -> {
|
||||
try {
|
||||
// Look up the function first so we can set an appropriate visibility
|
||||
// timeout: fn.timeout + 30s keeps messages hidden while Lambda runs.
|
||||
|
||||
Reference in new issue
Block a user