From 8af8aa34cd8bd33ed099b406d1622e6f2d25db23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=8E=E9=B8=A3?= Date: Sat, 11 Jul 2026 07:21:37 +0800 Subject: [PATCH] test: make TCP pull-mode reads deterministic Motivation: TcpConnectionSpec assumed data written on the server side was immediately readable by the client before ResumeReading. Under load, the non-blocking client read could return zero and the fake selector never delivered the later ChannelReadable notification. Modification: Assert each test payload is written in full and wait for the client channel to become readable before each pull-mode ResumeReading command. Result: The test preserves its one-Received-per-pull assertions without depending on loopback delivery timing. Tests: - JDK 25 focused pull-mode test, 10 consecutive runs: passed - JDK 25 full TcpConnectionSpec: 35 passed, 0 failed - sbt headerCreateAll +headerCheckAll checkCodeStyle: passed - scalafmt --list --mode diff-ref=origin/main: passed - git diff --check: passed - Qoder stdout review: no must-fix findings References: Refs #3311 --- .../scala/org/apache/pekko/io/TcpConnectionSpec.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/actor-tests/src/test/scala/org/apache/pekko/io/TcpConnectionSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/io/TcpConnectionSpec.scala index 5b0dc66100..f531a1a4a9 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/io/TcpConnectionSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/io/TcpConnectionSpec.scala @@ -395,15 +395,18 @@ class TcpConnectionSpec extends PekkoSpec(""" val maxBufferSize = 1 * 1024 val ts = "t" * maxBufferSize val us = "u" * (maxBufferSize / 2) + val tsAndUs = ts ++ us // send a batch that is bigger than the default buffer to make sure we don't recurse and // send more than one Received messages - serverSideChannel.write(ByteBuffer.wrap((ts ++ us).getBytes("ASCII"))) + serverSideChannel.write(ByteBuffer.wrap(tsAndUs.getBytes("ASCII"))) should ===(tsAndUs.length) + clientSelectionKey should be(selectedAs(OP_READ, remainingOrDefault)) connectionHandler.expectNoMessage(100.millis) connectionActor ! ResumeReading connectionHandler.expectMsgType[Received].data.decodeString("ASCII") should ===(ts) + clientSelectionKey should be(selectedAs(OP_READ, remainingOrDefault)) connectionHandler.expectNoMessage(100.millis) connectionActor ! ResumeReading @@ -412,7 +415,8 @@ class TcpConnectionSpec extends PekkoSpec(""" connectionHandler.expectNoMessage(100.millis) val vs = "v" * (maxBufferSize / 2) - serverSideChannel.write(ByteBuffer.wrap(vs.getBytes("ASCII"))) + serverSideChannel.write(ByteBuffer.wrap(vs.getBytes("ASCII"))) should ===(vs.length) + clientSelectionKey should be(selectedAs(OP_READ, remainingOrDefault)) connectionActor ! ResumeReading