Exemplo n.º 1
0
Arquivo: tests.py Projeto: pmdz/smite
 def __call__(self):
     client = Client()
     client.enable_security(self.client_secret, servant_public)
     client.connect(CONNECTION_URI)
     txt = uuid.uuid4().hex
     res = client.send(self.message_name, args=(txt,))
     assert res == txt
     client.close()
Exemplo n.º 2
0
Arquivo: tests.py Projeto: pmdz/smite
 def __call__(self):
     time.sleep(.3)
     client = Client()
     client.connect_tcp(host, proxy_port)
     txt = uuid.uuid4().hex
     res = client.send(self.message_name, args=(txt,))
     assert res == txt
     client.close()
Exemplo n.º 3
0
Arquivo: tests.py Projeto: pmdz/smite
    def send_msg(msg_name):
        client = Client(message_processors=(process_one, process_two))
        client.connect(CONNECTION_URI)

        msg_txt = uuid.uuid4().hex
        res = client.send(msg_name, args=(msg_txt,))
        assert res == msg_txt
        client.close()
Exemplo n.º 4
0
Arquivo: tests.py Projeto: pmdz/smite
def test_client_timeout():
    timeout = 3

    client = Client(default_timeout=timeout)
    client.connect(CONNECTION_URI)

    raised = False
    start = time.time()
    try:
        client.send('dummy_method')
    except ClientTimeout:
        raised = True

    assert raised

    # it should take around 3 seconds
    assert 2.5 < time.time() - start < 3.5

    # servant should not get this message after start, it's just gone
    class DummyException(Exception):
        pass

    def dummy_method():
        raise DummyException

    servant = Servant({'dummy_method': dummy_method})
    servant.bind_tcp(HOST, PORT)
    # run servant in separate thread and wait 3 seconds for message
    servant_thread = Thread(target=servant.run)
    servant_thread.start()
    time.sleep(3)
    servant.stop()
    servant_thread.join()
    client.close()

    for thread_stats in servant.stats['threads'].values():
        assert thread_stats['exceptions'] == 0
        assert thread_stats['received_messages'] == 0
        assert thread_stats['malicious_messages'] == 0
        assert thread_stats['processed_messages'] == 0

    assert servant.stats['summary']['exceptions'] == 0
    assert servant.stats['summary']['received_messages'] == 0
    assert servant.stats['summary']['malicious_messages'] == 0
    assert servant.stats['summary']['processed_messages'] == 0
Exemplo n.º 5
0
Arquivo: tests.py Projeto: pmdz/smite
def test_noreply_message():
    servant = Servant({'echo': lambda t: t})
    servant.bind_tcp(HOST, PORT)

    servant_thread = Thread(target=servant.run)
    servant_thread.start()

    client = Client()
    client.connect(CONNECTION_URI)
    client.send('echo', args=(uuid.uuid1().hex,), noreply=True)

    time.sleep(2)
    assert servant.stats['summary']['received_messages'] == 1
    assert servant.stats['summary']['processed_messages'] == 1

    servant.stop()
    servant_thread.join()
    client.close()