Skip to content

Commit 3bfae20

Browse files
committed
HDFS-14135. TestWebHdfsTimeouts Fails intermittently in trunk. Contributed by Ayush Saxena.
Signed-off-by: Masatake Iwasaki <[email protected]> (cherry picked from commit 6b8107a)
1 parent dc4d7f6 commit 3bfae20

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Arrays;
3636
import java.util.Collection;
3737
import java.util.List;
38+
import java.util.concurrent.TimeoutException;
3839

3940
import org.apache.commons.logging.Log;
4041
import org.apache.commons.logging.LogFactory;
@@ -47,6 +48,7 @@
4748
import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
4849
import org.apache.hadoop.test.GenericTestUtils;
4950
import org.junit.After;
51+
import org.junit.AssumptionViolatedException;
5052
import org.junit.Before;
5153
import org.junit.runner.RunWith;
5254
import org.junit.runners.Parameterized;
@@ -84,6 +86,7 @@ public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
8486
return conn;
8587
}
8688
});
89+
private volatile boolean failedToConsumeBacklog;
8790

8891
public enum TimeoutSource { ConnectionFactory, Configuration };
8992

@@ -122,6 +125,7 @@ public void setUp() throws Exception {
122125

123126
clients = new ArrayList<SocketChannel>();
124127
serverThread = null;
128+
failedToConsumeBacklog = false;
125129
}
126130

127131
@After
@@ -211,6 +215,7 @@ public void testRedirectConnectTimeout() throws Exception {
211215
fs.getFileChecksum(new Path("/file"));
212216
fail("expected timeout");
213217
} catch (SocketTimeoutException e) {
218+
assumeBacklogConsumed();
214219
GenericTestUtils.assertExceptionContains(
215220
fs.getUri().getAuthority() + ": connect timed out", e);
216221
}
@@ -244,6 +249,7 @@ public void testTwoStepWriteConnectTimeout() throws Exception {
244249
os = fs.create(new Path("/file"));
245250
fail("expected timeout");
246251
} catch (SocketTimeoutException e) {
252+
assumeBacklogConsumed();
247253
GenericTestUtils.assertExceptionContains(
248254
fs.getUri().getAuthority() + ": connect timed out", e);
249255
} finally {
@@ -357,6 +363,28 @@ private void consumeConnectionBacklog() throws IOException {
357363
client.connect(nnHttpAddress);
358364
clients.add(client);
359365
}
366+
try {
367+
GenericTestUtils.waitFor(() -> {
368+
try (SocketChannel c = SocketChannel.open()) {
369+
c.socket().connect(nnHttpAddress, 100);
370+
} catch (SocketTimeoutException e) {
371+
return true;
372+
} catch (IOException e) {
373+
LOG.debug("unexpected exception: " + e);
374+
}
375+
return false;
376+
}, 100, 10000);
377+
} catch (TimeoutException | InterruptedException e) {
378+
failedToConsumeBacklog = true;
379+
assumeBacklogConsumed();
380+
}
381+
}
382+
383+
private void assumeBacklogConsumed() {
384+
if (failedToConsumeBacklog) {
385+
throw new AssumptionViolatedException(
386+
"failed to fill up connection backlog.");
387+
}
360388
}
361389

362390
/**

0 commit comments

Comments
 (0)