From d0cc7384f90594c4a4b267ce5df98bf6d3ec5c94 Mon Sep 17 00:00:00 2001 From: Michael Pilquist Date: Fri, 8 May 2026 08:19:08 -0400 Subject: [PATCH] Fix intermittent test failures of WalkBenchmark in CI environments --- .../scala/fs2/io/file/WalkBenchmark.scala | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/io/jvm/src/test/scala/fs2/io/file/WalkBenchmark.scala b/io/jvm/src/test/scala/fs2/io/file/WalkBenchmark.scala index 155231c7c6..e4877c8e1e 100644 --- a/io/jvm/src/test/scala/fs2/io/file/WalkBenchmark.scala +++ b/io/jvm/src/test/scala/fs2/io/file/WalkBenchmark.scala @@ -68,23 +68,37 @@ class WalkBenchmark extends Fs2Suite { } test("Files.walk has similar performance to java.nio.file.Files.walk") { - val fs2Time = time( + def fs2Walk(): Long = Files[IO] .walk(target) .compile .count .unsafeRunSync() - ) - val fs2EagerTime = time( + + def fs2WalkEager(): Long = Files[IO] .walk(target, WalkOptions.Eager) .compile .count .unsafeRunSync() - ) - val nioTime = time(java.nio.file.Files.walk(target.toNioPath).count()) - val isOSX = sys.props("os.name") == "Mac OS X" - val factor = if (isOSX) 4.0 else 1.5 // OS X GHA workers tend to fail this test at 1.5x + + def nioWalk(): Long = + java.nio.file.Files.walk(target.toNioPath).count() + + val expectedCount = nioWalk() + assertEquals(fs2Walk(), expectedCount) + assertEquals(fs2WalkEager(), expectedCount) + + // Warm up all implementations first + fs2Walk() + fs2WalkEager() + nioWalk() + + val nioTime = time(nioWalk()) + val fs2Time = time(fs2Walk()) + val fs2EagerTime = time(fs2WalkEager()) + val isCI = sys.env.contains("CI") + val factor = if (isCI) 4.0 else 1.5 val epsilon = nioTime.toNanos * factor println(s"limit: ${epsilon.nanos.toMillis} ms") println(s"fs2 took: ${fs2Time.toMillis} ms")