From 3cb56eb514d02d0195f91c16691dea3f27ead2cb Mon Sep 17 00:00:00 2001 From: Travis Haagen Date: Sat, 12 Oct 2024 09:43:55 -0700 Subject: [PATCH] singleWorkerMultipleUsersWithLocustMasterEndingTest --- .../locust4k/examples/ExampleAppTest.kt | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/com/onepeloton/locust4k/examples/ExampleAppTest.kt b/src/test/kotlin/com/onepeloton/locust4k/examples/ExampleAppTest.kt index 72faccb..a17bf46 100644 --- a/src/test/kotlin/com/onepeloton/locust4k/examples/ExampleAppTest.kt +++ b/src/test/kotlin/com/onepeloton/locust4k/examples/ExampleAppTest.kt @@ -9,11 +9,24 @@ import java.time.Duration class ExampleAppTest : TestcontainersBase() { @Test fun singleWorkerWithLocustMasterEndingTest() { - val locustMasterContainer = buildLocustMasterContainer() + val locustMasterContainer = buildLocustMasterContainer(runtimeSeconds = 5) val locustWorkerExampleContainer = buildLocustWorkerExampleContainer() try { + // given startContainers(locustMasterContainer, locustWorkerExampleContainer) + LogMessageWaitStrategy() + .withRegEx(".*All users spawned.*\\s") + .withStartupTimeout(Duration.ofSeconds(5)) + .waitUntilReady(locustMasterContainer) + + LogMessageWaitStrategy() + .withTimes(2) + .withRegEx(".*Aggregated.*\\s") + .withStartupTimeout(Duration.ofSeconds(5)) + .waitUntilReady(locustMasterContainer) + + // when LogMessageWaitStrategy() .withRegEx(".* Receive Message producer ZMQ socket closed.*\\s") .withStartupTimeout(Duration.ofSeconds(5)) @@ -21,6 +34,7 @@ class ExampleAppTest : TestcontainersBase() { val workerLogs = locustWorkerExampleContainer.logs + // then assertThat( workerLogs, stringContainsInOrder( @@ -46,4 +60,63 @@ class ExampleAppTest : TestcontainersBase() { stopContainers(locustMasterContainer, locustWorkerExampleContainer) } } + + @Test + fun singleWorkerMultipleUsersWithLocustMasterEndingTest() { + val locustMasterContainer = buildLocustMasterContainer(users = 3, spawnRate = 2, runtimeSeconds = 5) + val locustWorkerExampleContainer = buildLocustWorkerExampleContainer() + try { + // given + startContainers(locustMasterContainer, locustWorkerExampleContainer) + + LogMessageWaitStrategy() + .withRegEx(".*All users spawned.*\\s") + .withStartupTimeout(Duration.ofSeconds(5)) + .waitUntilReady(locustMasterContainer) + + LogMessageWaitStrategy() + .withTimes(2) + .withRegEx(".*Aggregated.*\\s") + .withStartupTimeout(Duration.ofSeconds(5)) + .waitUntilReady(locustMasterContainer) + + // when + LogMessageWaitStrategy() + .withRegEx(".* Receive Message producer ZMQ socket closed.*\\s") + .withStartupTimeout(Duration.ofSeconds(5)) + .waitUntilReady(locustWorkerExampleContainer) + + val workerLogs = locustWorkerExampleContainer.logs + + // then + assertThat( + workerLogs, + stringContainsInOrder( + "Starting Locust Worker", + "Connected to Locust", + "Received ack", + "Spawn message from controller", + "Stats reset", + "+2 (-0) user-units", + "beforeExecuteLoop invoked", + "beforeExecuteLoop invoked", + "Spawn message from controller", + "+1 (-0) user-units", + "beforeExecuteLoop invoked", + "Spawning Complete", + "Quit message", + "afterExecuteLoop invoked", + "afterExecuteLoop invoked", + "afterExecuteLoop invoked", + "Stats consumer stopped", + "Stats reporter stopped", + "Shutting down Locust Worker", + "Closing connection", + "Receive Message producer ZMQ socket closed", + ), + ) + } finally { + stopContainers(locustMasterContainer, locustWorkerExampleContainer) + } + } }