def test_send_to_all(): conns = [mock.Mock() for i in range(10)] c = Connections('test', 'dummy') for i in conns: c._add(i, id(i)) c.send_to_all('foo') for i in conns: assert i.send_concurrent.called i.send_concurrent.assert_called_with(('test', 'dummy', 'foo'))
def test_send_to_many(): conns = [(i, mock.Mock()) for i in range(10)] c = Connections('test', 'dummy') for target, sock in conns: c._add(sock, target) targets = [2, 3, 5, 9] c.send(targets, 'foo') for i, sock in conns: assert sock.send_concurrent.called == (i in targets)
def test_heartbeat(): conns = [mock.Mock() for i in range(10)] c = Connections('test', 'dummy') for i in conns: c._add(i, id(i)) c.send_heartbeat() for i in conns: assert i.send_concurrent.called i.send_concurrent.assert_called_with(('test', 'dummy', HEARTBEAT))