Skip to content

Commit db074cd

Browse files
TomasHofmanfl4via
authored andcommitted
UNDERTOW-1859 Fix WriteTimeoutTestCase not terminating
1 parent c5d6800 commit db074cd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

core/src/test/java/io/undertow/server/WriteTimeoutTestCase.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.nio.ByteBuffer;
2424
import java.nio.channels.Channel;
25+
import java.nio.channels.ClosedChannelException;
2526
import java.util.concurrent.CountDownLatch;
2627
import java.util.concurrent.TimeUnit;
2728

@@ -31,7 +32,6 @@
3132
import org.apache.http.HttpResponse;
3233
import org.apache.http.client.methods.HttpGet;
3334
import org.junit.Assert;
34-
import org.junit.Ignore;
3535
import org.junit.Test;
3636
import org.junit.runner.RunWith;
3737
import org.xnio.ChannelListener;
@@ -47,7 +47,7 @@
4747
*/
4848
@RunWith(DefaultServer.class)
4949
@HttpOneOnly
50-
@Ignore("UNDERTOW-1859 this test freezes") //FIXME
50+
// @Ignore("UNDERTOW-1859 this test freezes") //FIXME
5151
public class WriteTimeoutTestCase {
5252

5353
private volatile Exception exception;
@@ -92,12 +92,10 @@ public void handleEvent(final Channel channel) {
9292
do {
9393
try {
9494
int res = response.write(buffer);
95-
if (res == 0) {
96-
return;
97-
}
9895
} catch (IOException e) {
9996
exception = e;
10097
errorLatch.countDown();
98+
break;
10199
}
102100
if(!buffer.hasRemaining()) {
103101
count++;
@@ -122,14 +120,20 @@ public void handleEvent(final Channel channel) {
122120
while ((r = content.read(buffer)) > 0) {
123121
Thread.sleep(200);
124122
if (exception != null) {
125-
Assert.assertEquals(WriteTimeoutException.class, exception.getClass());
123+
// Depending on whether the timeout is triggered inside XNIO or in the WriteTimeoutStreamSinkConduit,
124+
// we get either WriteTimeoutException or ClosedChannelException.
125+
Assert.assertTrue("Unexpected exception class: " + exception.getClass(),
126+
exception instanceof WriteTimeoutException || exception instanceof ClosedChannelException);
126127
return;
127128
}
128129
}
129130
Assert.fail("Write did not time out");
130131
} catch (IOException e) {
131132
if (errorLatch.await(5, TimeUnit.SECONDS)) {
132-
Assert.assertEquals(WriteTimeoutException.class, exception.getClass());
133+
// Depending on whether the timeout is triggered inside XNIO or in the WriteTimeoutStreamSinkConduit,
134+
// we get either WriteTimeoutException or ClosedChannelException.
135+
Assert.assertTrue("Unexpected exception class: " + exception.getClass(),
136+
exception instanceof WriteTimeoutException || exception instanceof ClosedChannelException);
133137
} else {
134138
Assert.fail("Write did not time out");
135139
}

0 commit comments

Comments
 (0)