import pytest
import zmq
import time


pytestmark = pytest.mark.control

@pytest.mark.broker
def test_broker_init(broker):
    assert broker.socket[0].getsockopt(zmq.TYPE) == zmq.ROUTER
    assert broker.socket[1].getsockopt(zmq.TYPE) == zmq.DEALER

@pytest.mark.boss
def test_boss_init(boss):
    assert boss.socket.getsockopt(zmq.TYPE) == zmq.REQ

@pytest.mark.worker
def test_worker_init(worker):
    assert worker.socket.getsockopt(zmq.TYPE) == zmq.REP

@pytest.mark.reqrep
def test_hw(boss, worker):
    worker.start()
    boss.start()
    time.sleep(3)
    worker.stop()
    boss.stop()
    assert worker.request == "Hello"
    assert boss.reply == "World"

def test_control(broker, boss, worker):
    broker.start()
    worker.start()
    boss.start()
    time.sleep(1)
    broker.stop()
    worker.stop()
    boss.stop()
    assert worker.request == "Hello"
    assert boss.reply == "World"
