Skip to content

Commit 85afd4b

Browse files
committed
Tests: Use dynamic ports
1 parent 1803f69 commit 85afd4b

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

AndroidAsyncTest/src/com/koushikdutta/async/test/CacheTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Environment;
44

55
import com.koushikdutta.async.AsyncServer;
6+
import com.koushikdutta.async.AsyncServerSocket;
67
import com.koushikdutta.async.http.AsyncHttpClient;
78
import com.koushikdutta.async.http.AsyncHttpGet;
89
import com.koushikdutta.async.http.ResponseCacheMiddleware;
@@ -36,13 +37,14 @@ public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse re
3637
}
3738
});
3839

39-
httpServer.listen(AsyncServer.getDefault(), 5555);
40+
AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
41+
int port = socket.getLocalPort();
4042
// clear the old cache
4143
cache.clear();
4244

43-
client.executeString(new AsyncHttpGet("http://localhost:5555/uname/43434"), null).get();
45+
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
4446

45-
client.executeString(new AsyncHttpGet("http://localhost:5555/uname/43434"), null).get();
47+
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
4648

4749

4850
assertEquals(cache.getCacheHitCount(), 1);

AndroidAsyncTest/src/com/koushikdutta/async/test/HttpClientTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.util.Log;
66

77
import com.koushikdutta.async.AsyncServer;
8+
import com.koushikdutta.async.AsyncServerSocket;
89
import com.koushikdutta.async.ByteBufferList;
910
import com.koushikdutta.async.DataEmitter;
1011
import com.koushikdutta.async.callback.CompletedCallback;
@@ -312,12 +313,12 @@ public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
312313
}
313314
});
314315

315-
httpServer.listen(proxyServer, 5555);
316+
AsyncServerSocket socket = httpServer.listen(proxyServer, 0);
316317

317318
// client.getSocketMiddleware().enableProxy("localhost", 5555);
318319

319320
AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
320-
get.enableProxy("localhost", 5555);
321+
get.enableProxy("localhost", socket.getLocalPort());
321322

322323
Future<String> ret = client.executeString(get, null);
323324
String data;

0 commit comments

Comments
 (0)