summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2016-12-20 16:03:11 +0000
committerYi Kong <yikong@google.com>2016-12-20 16:03:11 +0000
commit6a5e142b16cf6b921420d371c35d950a13b22db1 (patch)
treed4868a6230930aacf162a3d9ef2e1e2f3ec6384f /support
parent27a3e02d2dce24ad4f654f34959e33282e14dcbc (diff)
Remove StuckServer using backlog and tests relying on it
StuckServer uses kernel implementation details that have changed on version > 4.4, and causing tests depending on it to fail. Since we can't find an alternative method to simulate a stuck server without special permission, and the test itself is not reliable in that they don't fail on non-stuck servers, remove them from Libcore tests. Test: CtsLibcoreTestCases Bug: 32551747 Change-Id: I88d837329d65040a9f8550fff790f8703ea773f3
Diffstat (limited to 'support')
-rw-r--r--support/src/test/java/tests/net/StuckServer.java94
1 files changed, 0 insertions, 94 deletions
diff --git a/support/src/test/java/tests/net/StuckServer.java b/support/src/test/java/tests/net/StuckServer.java
deleted file mode 100644
index d6b038b7db..0000000000
--- a/support/src/test/java/tests/net/StuckServer.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.net;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-
-/**
- * A test ServerSocket that you can't connect to --- connects will time out.
- */
-public final class StuckServer {
- private static final boolean DEBUG = false;
-
- // RFC 5737 implies this network -- "test net 1" -- will be unreachable.
- // (There are two other networks to try if we have trouble with this one.)
- // We've had trouble with 10.* in the past (because test labs running CTS often use
- // net 10!) but hopefully this network will be better.
- public static final InetAddress UNREACHABLE_ADDRESS;
- static {
- try {
- UNREACHABLE_ADDRESS = InetAddress.getByAddress(new byte[] { (byte) 192, 0, 2, 0 });
- } catch (UnknownHostException ex) {
- throw new AssertionError(ex);
- }
- }
-
- private ServerSocket serverSocket;
- private InetSocketAddress address;
- private ArrayList<Socket> clients = new ArrayList<Socket>();
-
- public StuckServer(boolean useBacklog) throws IOException {
- // Set a backlog and use it up so that we can expect the
- // connection to time out. According to Stevens
- // 4.5 "listen function", Linux adds 3 to the specified
- // backlog, so we need to connect 4 times before it will hang.
- // The trouble with this is that it won't hang forever.
- // After 10s or so, the kernel allows a couple more connections.
- // This mode is ony useful if you actually want to continue eventually; we use it to
- // test non-blocking connects, for example, where you want to test every part of the code.
- if (useBacklog) {
- this.serverSocket = new ServerSocket(0, 1);
- this.address = (InetSocketAddress) serverSocket.getLocalSocketAddress();
- if (DEBUG) {
- System.err.println("StuckServer: " + serverSocket);
- }
- for (int i = 0; i < 4; ++i) {
- Socket client = new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort());
- clients.add(client);
- if (DEBUG) {
- System.err.println("StuckServer client " + i + " - " + client);
- }
- }
- } else {
- // In general, though, you don't want to rely on listen(2) backlog. http://b/6971145.
- this.address = new InetSocketAddress(UNREACHABLE_ADDRESS, 80);
- }
- }
-
- public InetSocketAddress getLocalSocketAddress() {
- return address;
- }
-
- public int getLocalPort() {
- return address.getPort();
- }
-
- public void close() throws IOException {
- if (serverSocket != null) {
- serverSocket.close();
- }
- for (Socket client : clients) {
- client.close();
- }
- }
-}