Skip to content

Commit

Permalink
singleWorkerMultipleUsersWithLocustMasterEndingTest
Browse files Browse the repository at this point in the history
  • Loading branch information
travishaagen committed Oct 12, 2024
1 parent 9808b73 commit 3cb56eb
Showing 1 changed file with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ 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))
.waitUntilReady(locustWorkerExampleContainer)

val workerLogs = locustWorkerExampleContainer.logs

// then
assertThat(
workerLogs,
stringContainsInOrder(
Expand All @@ -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)
}
}
}

0 comments on commit 3cb56eb

Please sign in to comment.