@@ -55,7 +55,7 @@ public class PipesClientInterruptTest {
5555 * open with an abandoned request on it.
5656 */
5757 @ Test
58- @ Timeout (30 )
58+ @ Timeout (45 )
5959 public void interruptClosesTheConnection () throws Exception {
6060 try (ServerSocket serverSocket = new ServerSocket (0 )) {
6161 CountDownLatch heartbeatStarted = new CountDownLatch (1 );
@@ -67,37 +67,36 @@ public void interruptClosesTheConnection() throws Exception {
6767
6868 PipesConfig pipesConfig = new PipesConfig ();
6969 SentinelServerManager manager = new SentinelServerManager (serverSocket .getLocalPort ());
70- PipesClient client = new PipesClient (pipesConfig , manager );
71-
72- AtomicReference <Throwable > fromProcess = new AtomicReference <>();
73- CountDownLatch processReturned = new CountDownLatch (1 );
74- Thread worker = new Thread (() -> {
75- try {
76- client .process (new FetchEmitTuple ("interrupt-test" ,
77- new FetchKey ("fetcher" , "key" ), new EmitKey (), new Metadata (),
78- new ParseContext (), FetchEmitTuple .ON_PARSE_EXCEPTION .SKIP ));
79- } catch (Throwable t ) {
80- fromProcess .set (t );
81- } finally {
82- processReturned .countDown ();
83- }
84- });
85- worker .start ();
70+ try (PipesClient client = new PipesClient (pipesConfig , manager )) {
71+ AtomicReference <Throwable > fromProcess = new AtomicReference <>();
72+ CountDownLatch processReturned = new CountDownLatch (1 );
73+ Thread worker = new Thread (() -> {
74+ try {
75+ client .process (new FetchEmitTuple ("interrupt-test" ,
76+ new FetchKey ("fetcher" , "key" ), new EmitKey (), new Metadata (),
77+ new ParseContext (), FetchEmitTuple .ON_PARSE_EXCEPTION .SKIP ));
78+ } catch (Throwable t ) {
79+ fromProcess .set (t );
80+ } finally {
81+ processReturned .countDown ();
82+ }
83+ });
84+ worker .start ();
8685
87- assertTrue (heartbeatStarted .await (15 , TimeUnit .SECONDS ),
88- "the scripted server never got the request; the test proves nothing" );
89- worker .interrupt ();
86+ assertTrue (heartbeatStarted .await (15 , TimeUnit .SECONDS ),
87+ "the scripted server never got the request; the test proves nothing" );
88+ worker .interrupt ();
9089
91- assertTrue (processReturned .await (15 , TimeUnit .SECONDS ),
92- "process() must return after the interrupt" );
93- assertTrue (fromProcess .get () instanceof InterruptedException ,
94- "process() must rethrow the interrupt, got: " + fromProcess .get ());
95- assertTrue (connectionClosed .await (5 , TimeUnit .SECONDS ),
96- "the interrupted client left its connection open with a request in flight" );
97- assertTrue (manager .abandoned ,
98- "the manager was not told; a per-client worker never dials back, so the "
99- + "next connect() would wait out the accept timeout for nothing" );
100- client . close ();
90+ assertTrue (processReturned .await (15 , TimeUnit .SECONDS ),
91+ "process() must return after the interrupt" );
92+ assertTrue (fromProcess .get () instanceof InterruptedException ,
93+ "process() must rethrow the interrupt, got: " + fromProcess .get ());
94+ assertTrue (connectionClosed .await (5 , TimeUnit .SECONDS ),
95+ "the interrupted client left its connection open with a request in flight" );
96+ assertTrue (manager .abandoned ,
97+ "the manager was not told; a per-client worker never dials back, so the "
98+ + "next connect() would wait out the accept timeout for nothing" );
99+ }
101100 }
102101 }
103102
@@ -109,7 +108,7 @@ public void interruptClosesTheConnection() throws Exception {
109108 * is delivered.
110109 */
111110 @ Test
112- @ Timeout (30 )
111+ @ Timeout (45 )
113112 public void interruptDuringStartupBackoffAbandonsTheConnection () throws Exception {
114113 try (ServerSocket serverSocket = new ServerSocket (0 )) {
115114 CountDownLatch badHandshakeSent = new CountDownLatch (1 );
@@ -120,38 +119,39 @@ public void interruptDuringStartupBackoffAbandonsTheConnection() throws Exceptio
120119 sentinel .start ();
121120
122121 PipesConfig pipesConfig = new PipesConfig ();
122+ // handshake reads aren't interrupt-responsive; a late interrupt waits this out
123+ pipesConfig .setStartupTimeoutMillis (1000 );
123124 SentinelServerManager manager = new SentinelServerManager (serverSocket .getLocalPort ());
124- PipesClient client = new PipesClient (pipesConfig , manager );
125-
126- AtomicReference <Throwable > fromProcess = new AtomicReference <>();
127- CountDownLatch processReturned = new CountDownLatch (1 );
128- Thread worker = new Thread (() -> {
129- try {
130- client .process (new FetchEmitTuple ("interrupt-startup-test" ,
131- new FetchKey ("fetcher" , "key" ), new EmitKey (), new Metadata (),
132- new ParseContext (), FetchEmitTuple .ON_PARSE_EXCEPTION .SKIP ));
133- } catch (Throwable t ) {
134- fromProcess .set (t );
135- } finally {
136- processReturned .countDown ();
137- }
138- });
139- worker .start ();
125+ try (PipesClient client = new PipesClient (pipesConfig , manager )) {
126+ AtomicReference <Throwable > fromProcess = new AtomicReference <>();
127+ CountDownLatch processReturned = new CountDownLatch (1 );
128+ Thread worker = new Thread (() -> {
129+ try {
130+ client .process (new FetchEmitTuple ("interrupt-startup-test" ,
131+ new FetchKey ("fetcher" , "key" ), new EmitKey (), new Metadata (),
132+ new ParseContext (), FetchEmitTuple .ON_PARSE_EXCEPTION .SKIP ));
133+ } catch (Throwable t ) {
134+ fromProcess .set (t );
135+ } finally {
136+ processReturned .countDown ();
137+ }
138+ });
139+ worker .start ();
140140
141- assertTrue (badHandshakeSent .await (15 , TimeUnit .SECONDS ),
142- "the scripted server never got a connection; the test proves nothing" );
143- worker .interrupt ();
141+ assertTrue (badHandshakeSent .await (15 , TimeUnit .SECONDS ),
142+ "the scripted server never got a connection; the test proves nothing" );
143+ worker .interrupt ();
144144
145- assertTrue (processReturned .await (15 , TimeUnit .SECONDS ),
146- "process() must return after the interrupt" );
147- assertTrue (fromProcess .get () instanceof InterruptedException ,
148- "process() must rethrow the interrupt, got: " + fromProcess .get ());
149- assertTrue (connectionClosed .await (5 , TimeUnit .SECONDS ),
150- "the interrupted client left its half-established connection open" );
151- assertTrue (manager .abandoned ,
152- "the manager was not told; an abandoned per-client worker never "
153- + "dials back, mid-handshake or not" );
154- client . close ();
145+ assertTrue (processReturned .await (15 , TimeUnit .SECONDS ),
146+ "process() must return after the interrupt" );
147+ assertTrue (fromProcess .get () instanceof InterruptedException ,
148+ "process() must rethrow the interrupt, got: " + fromProcess .get ());
149+ assertTrue (connectionClosed .await (5 , TimeUnit .SECONDS ),
150+ "the interrupted client left its half-established connection open" );
151+ assertTrue (manager .abandoned ,
152+ "the manager was not told; an abandoned per-client worker never "
153+ + "dials back, mid-handshake or not" );
154+ }
155155 }
156156 }
157157
0 commit comments