From b66e876c96fbc9c789d4159d4ab7647faea255e4 Mon Sep 17 00:00:00 2001 From: Tiberiu Breana Date: Tue, 18 Nov 2014 18:28:38 +0200 Subject: Add exceptions for test_connectLjava_net_SocketAddressI OldSocketTest's test_connectLjava_net_SocketAddressI would sometimes fail on certain networks. The connection attempt to the 'non-reachable' IP would be reset by a local router before the expected timeout occured, thus causing the test to fail. This change adds additional catch clauses for cases like this, looking for ECONNREFUSED messages. Bug: 18143878 Change-Id: I99a500d5c95cc25aa52ef231e6de43233f3e5316 Signed-off-by: Tiberiu Breana (cherry picked from commit d3ba3eb7a3fa67c1de2cb7a5ba999dcf91c13a91) --- luni/src/test/java/libcore/java/net/OldSocketTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'luni') diff --git a/luni/src/test/java/libcore/java/net/OldSocketTest.java b/luni/src/test/java/libcore/java/net/OldSocketTest.java index 80bee69..7973965 100644 --- a/luni/src/test/java/libcore/java/net/OldSocketTest.java +++ b/luni/src/test/java/libcore/java/net/OldSocketTest.java @@ -1251,6 +1251,12 @@ public class OldSocketTest extends OldSocketTestCase { theSocket.connect(nonReachableAddress, 200); theSocket.close(); fail("No interrupted exception when connecting to address nobody listening on with short timeout 200: "); + } catch (ConnectException ce) { + // some networks will quickly reset the TCP connection attempt to this fake IP + assertTrue( + "Wrong exception when connecting to address nobody listening on with short timeout 200: " + + ce.toString(), + (ce.getMessage() != null && ce.getMessage().contains("ECONNREFUSED"))); } catch (Exception e) { assertTrue( "Wrong exception when connecting to address nobody listening on with short timeout 200: " @@ -1266,6 +1272,12 @@ public class OldSocketTest extends OldSocketTestCase { theSocket.connect(nonReachableAddress, 40); theSocket.close(); fail("No interrupted exception when connecting to address nobody listening on with short timeout 40: "); + } catch (ConnectException ce) { + // some networks will quickly reset the TCP connection attempt to this fake IP + assertTrue( + "Wrong exception when connecting to address nobody listening on with short timeout 40: " + + ce.toString(), + (ce.getMessage() != null && ce.getMessage().contains("ECONNREFUSED"))); } catch (Exception e) { assertTrue( "Wrong exception when connecting to address nobody listening on with short timeout 40: " -- cgit v1.1