@@ -96,7 +96,6 @@ public class StreamingSubscriberConnectionTest {
9696
9797 private static final long KEEP_ALIVE_SUPPORT_VERSION = 1 ;
9898 private static final Duration CLIENT_PING_INTERVAL = Duration .ofSeconds (30 );
99- private static final Duration SERVER_TIMEOUT_DURATION = Duration .ofSeconds (45 );
10099 private static final Duration MAX_ACK_EXTENSION_PERIOD = Duration .ofMinutes (60 );
101100
102101 @ Before
@@ -703,8 +702,8 @@ public void testClientPinger_pingSent() {
703702
704703 ArgumentCaptor <StreamingPullRequest > requestCaptor =
705704 ArgumentCaptor .forClass (StreamingPullRequest .class );
706- // 1 initial request + 2 pings
707- verify (mockClientStream , times (3 )).send (requestCaptor .capture ());
705+ // 1 initial request + 3 pings
706+ verify (mockClientStream , times (4 )).send (requestCaptor .capture ());
708707 List <StreamingPullRequest > requests = requestCaptor .getAllValues ();
709708
710709 StreamingPullRequest initialRequest = requests .get (0 );
@@ -723,7 +722,7 @@ public void testClientPinger_pingSent() {
723722
724723 // No more pings
725724 systemExecutor .advanceTime (CLIENT_PING_INTERVAL );
726- verify (mockClientStream , times (3 )).send (any (StreamingPullRequest .class ));
725+ verify (mockClientStream , times (4 )).send (any (StreamingPullRequest .class ));
727726 }
728727
729728 @ Test
@@ -769,7 +768,7 @@ public void testServerMonitor_timesOut() {
769768 StreamingPullRequest req = invocation .getArgument (0 );
770769 // Pings are empty requests
771770 if (req .getSubscription ().isEmpty ()) {
772- if (pingCount .incrementAndGet () > 1 ) { // allow first ping
771+ if (pingCount .incrementAndGet () > 2 ) { // allow first 2 pings
773772 throw new RuntimeException ("ping failed" );
774773 }
775774 }
@@ -788,15 +787,10 @@ public void testServerMonitor_timesOut() {
788787 StreamController mockController = mock (StreamController .class );
789788 observer .onStart (mockController );
790789
791- // Pings are sent every 30s, monitor checks every 15s. Timeout is 15s after ping if no response.
792- // t=30s: first ping sent, lastClientPingTime=30s.
793- // t=45s: monitor check. now=45, lastPing=30. 45-30=15. 15>15 is false. No timeout.
794- systemExecutor .advanceTime (SERVER_TIMEOUT_DURATION );
790+ systemExecutor .advanceTime (CLIENT_PING_INTERVAL );
795791 verify (mockClientStream , never ()).closeSendWithError (any (Exception .class ));
796792
797- // t=60s: second ping fails to send. lastClientPingTime remains 30s.
798- // t=60s: monitor check. now=60, lastPing=30. 60-30=30. 30>15 is true. Timeout.
799- systemExecutor .advanceTime (Duration .ofSeconds (16 ));
793+ systemExecutor .advanceTime (CLIENT_PING_INTERVAL );
800794 ArgumentCaptor <Exception > exceptionCaptor = ArgumentCaptor .forClass (Exception .class );
801795 verify (mockClientStream , times (1 )).closeSendWithError (exceptionCaptor .capture ());
802796 StatusException exception = (StatusException ) exceptionCaptor .getValue ();
@@ -832,6 +826,7 @@ public void testServerMonitor_doesNotTimeOutIfResponseReceived() {
832826 systemExecutor .advanceTime (Duration .ofSeconds (40 ));
833827 observer .onResponse (StreamingPullResponse .getDefaultInstance ());
834828 systemExecutor .advanceTime (Duration .ofSeconds (20 )); // to t=60s
829+ observer .onResponse (StreamingPullResponse .getDefaultInstance ());
835830
836831 verify (mockClientStream , never ()).closeSendWithError (any (Exception .class ));
837832 }
0 commit comments