def test_getClientFor_errors_when_no_connections(self): service = RegionService(sentinel.ipcWorker) service.connections.clear() return assert_fails_with( service.getClientFor(factory.make_UUID(), timeout=0), exceptions.NoConnectionsAvailable, )
def test_getClientFor_returns_random_connection(self): c1 = DummyConnection() c2 = DummyConnection() chosen = DummyConnection() service = RegionService(sentinel.ipcWorker) uuid = factory.make_UUID() conns_for_uuid = service.connections[uuid] conns_for_uuid.update({c1, c2}) def check_choice(choices): self.assertItemsEqual(choices, conns_for_uuid) return chosen self.patch(random, "choice", check_choice) def check(client): self.assertThat(client, Equals(RackClient(chosen, {}))) self.assertIs(client.cache, service.connectionsCache[client._conn]) return service.getClientFor(uuid).addCallback(check)