Skip to content

Commit

Permalink
Refactor runLoadBalancerTest a little
Browse files Browse the repository at this point in the history
The routeIds size assertion failed on CI:
```
org.junit.ComparisonFailure: expected:<[2]> but was:<[1]>
```
Now we should get a bit better error message.
We will see the singular route and its count.
We might see that it's not the full 1000.
Or it might just show a single route with 1000 count.

We'll also get another CI trigger and see if it was a flake.
It' s possible that the problem existed for a longer time,
but `OracleJDK` flakiness was covering it up.
  • Loading branch information
dagguh committed Jun 24, 2024
1 parent be5741d commit d5484ab
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.net.URI
import java.time.Duration
import java.time.Duration.ofSeconds
import java.util.*
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletableFuture.completedFuture
import java.util.concurrent.Executors.newFixedThreadPool
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -70,7 +70,7 @@ class DataCenterFormulaIT {
),
pluginsTransport = aws.jiraStorage(nonce),
resultsTransport = aws.resultsStorage(nonce),
key = CompletableFuture.completedFuture(keyFormula.provision()),
key = completedFuture(keyFormula.provision()),
roleProfile = aws.shortTermStorageAccess(),
aws = aws
)
Expand All @@ -87,28 +87,26 @@ class DataCenterFormulaIT {
val executor = newFixedThreadPool(20) { Thread(it, "DCFIT-test-load-balancer-thread-$it") }

val routeIds = (1..1000).map {
executor.submitWithLogContext("Test") {
executor.submitWithLogContext("route-$it") {
getRouteId(address)
}
}
.map { it.get() }
.groupingBy { it }
.eachCount()

assertThat(routeIds.size).isEqualTo(2)
assertThat(routeIds).hasSize(2)

val counts = routeIds.entries.map { it.value }
assertThat(counts[0]).isCloseTo(counts[1], withPercentage(10.0))
}

private fun getRouteId(address: URI): String {
val cookiesList = address.toURL().openConnection().headerFields["Set-Cookie"]
assertThat(cookiesList).isNotNull()
val routeId = cookiesList!!.filter { str ->
str.contains("ROUTEID")
}
assertThat(routeId).hasSize(1)
return routeId[0].split(";")[0]
val headers = address.toURL().openConnection().headerFields
assertThat(headers).containsKey("Set-Cookie")
val routeIds = headers["Set-Cookie"]!!.filter { it.contains("ROUTEID") }
assertThat(routeIds).hasSize(1)
return routeIds.single().split(";").first()
}

@Test
Expand All @@ -132,7 +130,7 @@ class DataCenterFormulaIT {
investment = investment,
pluginsTransport = aws.jiraStorage(nonce),
resultsTransport = aws.resultsStorage(nonce),
key = CompletableFuture.completedFuture(keyFormula.provision()),
key = completedFuture(keyFormula.provision()),
roleProfile = aws.shortTermStorageAccess(),
aws = aws
)
Expand Down

0 comments on commit d5484ab

Please sign in to comment.