mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(lambda): trigger scheduled repair callbacks deterministically (#7477)
This commit is contained in:
1 parent
ca54394bf0
commit
d098a4729a
2 files changed
+27
-5
No files matched your search
+16
-3
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Clock;
|
||||
@@ -37,6 +38,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -773,17 +775,28 @@ class ProvisionedConcurrencyPoolTest {
|
||||
LambdaAliasStore aliasLookup = spy(aliases);
|
||||
doThrow(new IllegalStateException("controlled scheduler lookup outage"))
|
||||
.when(aliasLookup).getForAccount(ACCOUNT, REGION, "example", "live");
|
||||
ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
|
||||
pool = new ProvisionedConcurrencyPool(launcher, functions, aliasLookup,
|
||||
storage, Clock.systemUTC(), 4, 8, false, 15);
|
||||
storage, Clock.systemUTC(), 4, 8, false, 15, scheduler);
|
||||
pool.start();
|
||||
await().atMost(Duration.ofSeconds(5)).untilAsserted(() ->
|
||||
verify(aliasLookup, atLeast(2)).getForAccount(ACCOUNT, REGION, "example", "live"));
|
||||
ArgumentCaptor<Runnable> repair = ArgumentCaptor.forClass(Runnable.class);
|
||||
verify(scheduler).scheduleWithFixedDelay(repair.capture(), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
|
||||
repair.getValue().run();
|
||||
await().atMost(Duration.ofSeconds(3)).untilAsserted(() ->
|
||||
verify(aliasLookup, times(1)).getForAccount(ACCOUNT, REGION, "example", "live"));
|
||||
repair.getValue().run();
|
||||
await().atMost(Duration.ofSeconds(3)).untilAsserted(() ->
|
||||
verify(aliasLookup, times(2)).getForAccount(ACCOUNT, REGION, "example", "live"));
|
||||
doCallRealMethod().when(aliasLookup).getForAccount(ACCOUNT, REGION, "example", "live");
|
||||
repair.getValue().run();
|
||||
await().atMost(Duration.ofSeconds(3)).until(() -> !launcher.launched.isEmpty());
|
||||
Environment replacement = launched();
|
||||
replacement.initialized.complete(null);
|
||||
ready();
|
||||
assertEquals("READY", get().status());
|
||||
assertEquals(1, first.stops.get());
|
||||
pool.shutdown();
|
||||
verify(scheduler).shutdownNow();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user