-
Notifications
You must be signed in to change notification settings - Fork 1
fix flaky tests because of ZTestLogger #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,27 @@ import zio.test.TestAspect.withLiveClock | |||||||
| import zio.{ZIO, durationInt} | ||||||||
| import zio.raft.LogEntry.NoopLogEntry | ||||||||
| import zio.raft.LogEntry.CommandLogEntry | ||||||||
| import zio.LogLevel | ||||||||
| import zio.ZLogger | ||||||||
| import zio.Cause | ||||||||
| import zio.FiberId | ||||||||
| import zio.FiberRefs | ||||||||
| import zio.LogSpan | ||||||||
| import zio.Trace | ||||||||
| import java.util.concurrent.ConcurrentLinkedQueue | ||||||||
| import scala.jdk.CollectionConverters._ | ||||||||
|
|
||||||||
| object RaftIntegrationSpec extends ZIOSpecDefault: | ||||||||
|
|
||||||||
| // We use TestLogger instead of ZTestLogger because ZTestLogger can cause duplicated log lines whcih causes flakiness in our tests. | ||||||||
| class TestLogger extends ZLogger[String, Unit] { | ||||||||
| var messages: ConcurrentLinkedQueue[String] = new ConcurrentLinkedQueue() | ||||||||
keisar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| override def apply(trace: Trace, fiberId: FiberId, logLevel: LogLevel, message: () => String, cause: Cause[Any], context: FiberRefs, spans: List[LogSpan], annotations: Map[String, String]): Unit = | ||||||||
| messages.add(message()) | ||||||||
|
||||||||
| messages.add(message()) | |
| { messages.add(message()); () } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect, check again
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counting log messages directly from a ConcurrentLinkedQueue immediately after readState can race with late asynchronous log emissions, potentially reintroducing flakiness (only the first test is marked flaky). Consider synchronizing by awaiting completion of pending fibers or introducing a short drain/settle step (e.g., ZIO.sleep(...)) before snapshotting messages, or capturing log entries with a timestamp and filtering only those emitted before readState completes.
| // Allow time for any late log emissions to settle before snapshotting messages | |
| _ <- ZIO.sleep(100.millis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a very nice point, since I tested with nonFlaky I think we're good for now
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counting log messages directly from a ConcurrentLinkedQueue immediately after readState can race with late asynchronous log emissions, potentially reintroducing flakiness (only the first test is marked flaky). Consider synchronizing by awaiting completion of pending fibers or introducing a short drain/settle step (e.g., ZIO.sleep(...)) before snapshotting messages, or capturing log entries with a timestamp and filtering only those emitted before readState completes.
Uh oh!
There was an error while loading. Please reload this page.