Skip to content

Commit 2583dfa

Browse files
committed
Fix flaky MetricsSpec test
Use longer report period (500ms) with longer sleep (550ms) to provide a 450ms buffer before the second report cycle. This eliminates the race condition where a second report could reset the gauge value to zero before the test captures metrics.
1 parent 9f0fb28 commit 2583dfa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

modules/it/src/test/scala/com/snowplowanalytics/snowplow/runtime/MetricsSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class MetricsSpec extends CatsResource[IO, (GenericContainer[_], StatsdAPI[IO])]
4040

4141
def e1 = withResource { case (statsd @ _, statsdApi) =>
4242
for {
43-
t <- TestMetrics.impl
43+
t <- TestMetrics.impl(500.millis)
4444
_ <- t.count(100)
4545
_ <- t.time(10.seconds)
4646
f <- t.report.compile.drain.start
47-
_ <- IO.sleep(150.millis)
47+
_ <- IO.sleep(550.millis)
4848
counters <- statsdApi
4949
.get(Metrics.MetricType.Count)
5050
.retryingOnFailures(
@@ -81,7 +81,7 @@ object TestMetrics {
8181
def time(t: FiniteDuration) = ref.update(s => s.copy(timer = s.timer + t))
8282
}
8383

84-
def impl = Ref[IO]
84+
def impl(period: FiniteDuration) = Ref[IO]
8585
.of(TestState.empty)
8686
.map { ref =>
8787
TestMetrics(
@@ -92,7 +92,7 @@ object TestMetrics {
9292
"localhost",
9393
8125,
9494
Map.empty,
95-
100.millis,
95+
period,
9696
""
9797
)
9898
)

0 commit comments

Comments
 (0)