Skip to content

Commit cc35563

Browse files
adamwclaude
andcommitted
Fix FutureMonadTest flakiness on Scala 2.12 under CI load
The test used `intercept[RuntimeException]` around `.futureValue`, but `TestFailedException` (thrown on timeout) is a `RuntimeException` subclass. On a loaded CI machine, the 150ms default patience expired before the finalizer future completed, causing the intercept to silently catch the timeout instead of the expected "boom!" exception. Result: `ran.get` was `false` even though `intercept` appeared to succeed. Fix: mix in `ScalaFutures` to allow a 10s patience override, and use `.failed.futureValue` so a timeout throws `TestFailedException` uncaught rather than being mistaken for the expected exception. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 484bbe5 commit cc35563

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package sttp.monad
22

3-
import org.scalatest.concurrent.ScalaFutures.convertScalaFuture
3+
import org.scalatest.concurrent.ScalaFutures
44
import org.scalatest.flatspec.AnyFlatSpec
55
import org.scalatest.matchers.should.Matchers
6+
import org.scalatest.time.{Seconds, Span}
67

78
import java.util.concurrent.atomic.AtomicBoolean
89
import scala.concurrent.ExecutionContext.Implicits.global
910
import scala.concurrent.Future
1011

11-
class FutureMonadTest extends AnyFlatSpec with Matchers {
12+
class FutureMonadTest extends AnyFlatSpec with Matchers with ScalaFutures {
13+
implicit override val patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(10, Seconds))
1214
implicit val m: MonadError[Future] = new FutureMonad()
1315

1416
it should "ensure" in {
1517
val ran = new AtomicBoolean(false)
1618

17-
intercept[RuntimeException] {
18-
m.ensure2((throw new RuntimeException("boom!")): Future[Int], Future(ran.set(true))).futureValue
19-
}
20-
19+
val result = m.ensure2((throw new RuntimeException("boom!")): Future[Int], Future(ran.set(true)))
20+
result.failed.futureValue shouldBe a[RuntimeException]
2121
ran.get shouldBe true
2222
}
2323
}

0 commit comments

Comments
 (0)