private void aggressivelyCloseClients() throws Exception { clients.forEach( client -> { client.dispatcher().executorService().shutdown(); Observable.interval(100, TimeUnit.MILLISECONDS) .takeUntil( i -> { boolean canEvict = client.connectionPool().idleConnectionCount() == client.connectionPool().connectionCount(); client.connectionPool().evictAll(); return canEvict; }) .timeout(15, TimeUnit.SECONDS) .blockingSubscribe(); }); }