def run_traffic_jam(nsends, nbytes): # This test eats `nsends * nbytes` bytes in RAM np = pytest.importorskip('numpy') from distributed.protocol import to_serialize data = bytes(np.random.randint(0, 255, size=(nbytes, )).astype('u1').data) with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=0.01) b.start(comm) msg = {'x': to_serialize(data)} for i in range(nsends): b.send(assoc(msg, 'i', i)) if np.random.random() > 0.5: yield gen.sleep(0.001) results = [] count = 0 while len(results) < nsends: # If this times out then I think it's a backpressure issue # Somehow we're able to flood the socket so that the receiving end # loses some of our messages L = yield gen.with_timeout(timedelta(seconds=5), comm.read()) count += 1 results.extend(r['i'] for r in L) assert count == b.batch_count == e.count assert b.message_count == nsends assert results == list(range(nsends)) comm.close() # external closing yield b.close()
def run_traffic_jam(nsends, nbytes): # This test eats `nsends * nbytes` bytes in RAM np = pytest.importorskip('numpy') from distributed.protocol import to_serialize data = bytes(np.random.randint(0, 255, size=(nbytes,)).astype('u1').data) with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=0.01) b.start(comm) msg = {'x': to_serialize(data)} for i in range(nsends): b.send(assoc(msg, 'i', i)) if np.random.random() > 0.5: yield gen.sleep(0.001) results = [] count = 0 while len(results) < nsends: # If this times out then I think it's a backpressure issue # Somehow we're able to flood the socket so that the receiving end # loses some of our messages L = yield gen.with_timeout(timedelta(seconds=5), comm.read()) count += 1 results.extend(r['i'] for r in L) assert count == b.batch_count == e.count assert b.message_count == nsends assert results == list(range(nsends)) comm.close() # external closing yield b.close()
def test_close_twice(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) yield b.close() yield b.close()
def test_close_twice(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) yield b.close() yield b.close()
def test_close_twice(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) yield b.close() yield b.close()
def test_close_twice(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) yield b.close() yield b.close()
def test_close_closed(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) b.send(123) comm.close() # external closing yield b.close()
def test_close_closed(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) b.send(123) stream.close() # external closing yield b.close(ignore_closed=True)
def test_close_closed(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) b.send(123) stream.close() # external closing yield b.close(ignore_closed=True)
def test_close_closed(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) b.send(123) comm.close() # external closing yield b.close() assert 'closed' in repr(b) assert 'closed' in str(b)
def test_send_before_close(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) cnt = int(e.count) b.send('hello') yield b.close() # close immediately after sending assert not b.buffer start = time() while e.count != cnt + 1: yield gen.sleep(0.01) assert time() < start + 5 with pytest.raises(CommClosedError): b.send('123')
def test_send_before_close(): with echo_server() as e: comm = yield connect(e.address) b = BatchedSend(interval=10) b.start(comm) cnt = int(e.count) b.send('hello') yield b.close() # close immediately after sending assert not b.buffer start = time() while e.count != cnt + 1: yield gen.sleep(0.01) assert time() < start + 5 with pytest.raises(CommClosedError): b.send('123')
def test_send_before_close(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) cnt = int(e.count) b.send('hello') yield b.close() # close immediately after sending assert not b.buffer start = time() while e.count != cnt + 1: yield gen.sleep(0.01) assert time() < start + 5 with pytest.raises(StreamClosedError): b.send('123')
def test_send_before_close(): with echo_server() as e: client = TCPClient() stream = yield client.connect('127.0.0.1', e.port) b = BatchedSend(interval=10) b.start(stream) cnt = int(e.count) b.send('hello') yield b.close() # close immediately after sending assert not b.buffer start = time() while e.count != cnt + 1: yield gen.sleep(0.01) assert time() < start + 5 with pytest.raises(StreamClosedError): b.send('123')
def test_close_not_started(): b = BatchedSend(interval=10) yield b.close()
def test_close_not_started(): b = BatchedSend(interval=10) yield b.close()