Skip to content

Commit da68130

Browse files
joybestourousjenkins
authored andcommitted
finatra: fix flaky tests
Problem: Some of our github actions have been failing due to the following tests: In our `InMemoryStatsReceiverUtilityTest`, by the time we get to the waitFor call, the metrics have already been updated too many times. In `FeatureTestNonInjectionCustomStatsReceiverTest`, we check that our gauges are nonempty because they should be populated at startup, but occasionally the server is not fully started before our check. Solution: For `InMemoryStatsReceiverUtilityTest`, we'll call `waitFor` in its own thread before adding to stats, counters, gauges For `FeatureTestNonInjectionCustomStatsReceiverTest`, we'll wait for the server to complete startup before running any tests JIRA Issues: CSL-11274 Differential Revision: https://phabricator.twitter.biz/D766267
1 parent cf44ba8 commit da68130

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

inject/inject-core/src/test/scala/com/twitter/inject/tests/InMemoryStatsReceiverUtilityTest.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.twitter.inject.tests
22

33
import com.twitter.finagle.stats.InMemoryStatsReceiver
4-
import com.twitter.inject.{InMemoryStatsReceiverUtility, Test}
4+
import com.twitter.inject.InMemoryStatsReceiverUtility
5+
import com.twitter.inject.Test
56
import com.twitter.conversions.DurationOps._
67
import com.twitter.util.FuturePool
78
import org.scalatest.exceptions.TestFailedDueToTimeoutException
@@ -68,32 +69,35 @@ class InMemoryStatsReceiverUtilityTest extends Test {
6869
var gaugeValue: Float = 0.0f
6970
val gauge = inMemoryStatsReceiver.addGauge("gauge") { gaugeValue }
7071

72+
val counterWait = FuturePool.unboundedPool { sr.counters.waitFor("counter", 1L, timeout) }
7173
// Change metrics every 20 millis
72-
val increaseCounter = FuturePool.unboundedPool {
74+
FuturePool.unboundedPool {
7375
for (_ <- 0 to 2) {
7476
Thread.sleep(20)
7577
// counter values: 0L, 1L, 2L, 3L
7678
counter.incr()
7779
}
7880
}
79-
sr.counters.waitFor("counter", 1L, timeout)
81+
await(counterWait)
8082

81-
val addToHistogram = FuturePool.unboundedPool {
83+
val statsWait = FuturePool.unboundedPool { sr.stats.waitFor("stat", Seq(0.0f, 1.0f), timeout) }
84+
FuturePool.unboundedPool {
8285
for (s <- 0 to 2) {
8386
Thread.sleep(20)
8487
// histogram values: Seq(0.0f, 1.0f, 2.0f)
8588
stat.add(s)
8689
}
8790
}
88-
sr.stats.waitFor("stat", Seq(0.0f, 1.0f), timeout)
91+
await(statsWait)
8992

90-
val increaseGauge = FuturePool.unboundedPool {
93+
val gaugeWait = FuturePool.unboundedPool { sr.gauges.waitFor("gauge", 1.0f, timeout) }
94+
FuturePool.unboundedPool {
9195
for (g <- 0 to 2) {
9296
Thread.sleep(20)
9397
// gauge values: 0.0f, 1.0f, 2.0f
9498
gaugeValue = g
9599
}
96100
}
97-
sr.gauges.waitFor("gauge", 1.0f, timeout)
101+
await(gaugeWait)
98102
}
99103
}

inject/inject-server/src/test/scala/com/twitter/inject/server/tests/FeatureTestNonInjectionCustomStatsReceiverTest.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.twitter.inject.server.tests
22

33
import com.twitter.finagle.http.Status
4-
import com.twitter.inject.server.{EmbeddedTwitterServer, FeatureTest}
4+
import com.twitter.inject.server.EmbeddedTwitterServer
5+
import com.twitter.inject.server.FeatureTest
56

67
/** Test a non-inject TwitterServer using a Custom StatsReceiver implementation with the [[FeatureTest]] trait */
78
class FeatureTestNonInjectionCustomStatsReceiverTest extends FeatureTest {
@@ -24,6 +25,7 @@ class FeatureTestNonInjectionCustomStatsReceiverTest extends FeatureTest {
2425
*/
2526
override def beforeAll(): Unit = {
2627
server.start()
28+
super.beforeAll()
2729
}
2830

2931
test("TestServer#starts up") {

0 commit comments

Comments
 (0)