def test_slave_recv_request(build_state, file_state): slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') with mock.patch('piwheels.master.states.datetime') as dt: now = datetime.utcnow() dt.utcnow.return_value = now assert slave_state.last_seen is None slave_state.request = ['IDLE'] assert slave_state.request == ['IDLE'] assert slave_state.last_seen == now assert slave_state.build is None now = datetime.utcnow() dt.utcnow.return_value = now slave_state._reply = ['BUILD', 'foo', '0.1'] slave_state.request = [ 'BUILT', build_state.status, build_state.duration, build_state.output, { file_state.filename: ( file_state.filesize, file_state.filehash, file_state.package_tag, file_state.package_version_tag, file_state.py_version_tag, file_state.abi_tag, file_state.platform_tag, file_state.dependencies ) } ] assert slave_state.last_seen == now build_state._slave_id = slave_state.slave_id assert slave_state.build == build_state
def test_slave_state_expired(): slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') slave_state._first_seen = datetime.utcnow() - timedelta(hours=5) assert not slave_state.expired slave_state._last_seen = datetime.utcnow() - timedelta(hours=4) assert slave_state.expired
def test_slave_recv_bad_built(build_state, file_state, slave_queue): slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') with mock.patch('piwheels.master.states.datetime') as dt: now = datetime.utcnow() dt.utcnow.return_value = now slave_state._reply = ['BUILD', 'foo', '0.1'] slave_state.request = ['BUILT'] assert slave_state.build is None slave_state.reply = ['DONE'] assert slave_state.build is None
def test_slave_state_hello(master_status_queue, slave_queue): with mock.patch('piwheels.master.states.datetime') as dt: now = datetime.utcnow() dt.utcnow.return_value = now slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') slave_state.reply = ['HELLO', slave_state.slave_id, const.PYPI_XMLRPC] assert master_status_queue.recv_pyobj() == [ slave_state.slave_id, now, 'HELLO', timedelta(hours=3), '34', 'cp34m', 'linux_armv7l', 'piwheels2' ]
def test_slave_state_init(): now = datetime.utcnow() with mock.patch('piwheels.master.states.datetime') as dt: dt.utcnow.return_value = now slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') assert slave_state.slave_id == 1 assert slave_state.address == '10.0.0.2' assert slave_state.label == 'piwheels2' assert slave_state.timeout == timedelta(hours=3) assert slave_state.native_py_version == '34' assert slave_state.native_abi == 'cp34m' assert slave_state.native_platform == 'linux_armv7l' assert slave_state.first_seen == now assert slave_state.last_seen is None assert slave_state.request is None assert slave_state.reply is None assert slave_state.build is None assert not slave_state.terminated
def test_slave_state_kill(): slave_state = SlaveState('10.0.0.2', 3 * 60 * 60, '34', 'cp34m', 'linux_armv7l', 'piwheels2') assert not slave_state.terminated slave_state.kill() assert slave_state.terminated