def test_command_state(self): command = Command('command-1') assert_that(command.state(), is_(State.QUEUED)) command.start() assert_that(command.state(), is_(State.STARTED)) command.done() assert_that(command.state(), is_(State.DONE))
def test_command_finished(self): command = Command('command-1') assert_that(command.is_finished(), is_(False)) command.start() assert_that(command.is_finished(), is_(False)) command.done() assert_that(command.is_finished(), is_(True))
def test_command_fail_result(self): command = Command('command-1') assert_that(command.state(), is_(State.QUEUED)) command.start() assert_that(command.state(), is_(State.STARTED)) command.fail('failed') assert_that(command.state(), is_(State.FAIL)) assert_that(command.result, is_('failed'))
def test_queue(self): queue = MemoryCommandQueue() queue.add_command('runtime-1', Command('test')) queue.add_command('runtime-1', Command('test')) commands = queue.get_queued_commands('runtime-1') assert_that(commands, has_length(2)) commands = queue.get_queued_commands('runtime-2') assert_that(commands, has_length(0)) commands = queue.get_queued_commands('runtime-1', 2) assert_that(commands, has_length(0))
def test_set_result(self): queue = MemoryCommandQueue() queue.add_command('runtime-1', Command('test')) # seq_id: 1 queue.add_command('runtime-1', Command('test')) # seq_id: 2 queue.set_command_result('runtime-1', 1, True, 100) commands = queue.get_queued_commands('runtime-1') assert_that(commands, has_length(1)) command = queue._get_command('runtime-1', 1) assert_that(command.state(), is_(State.DONE)) assert_that(command.result, is_(100))
def test_queue_cmd_state(self): queue = MemoryCommandQueue() queue.add_command('runtime-1', Command('test')) queue.add_command('runtime-1', Command('test')) commands = queue.get_queued_commands('runtime-1') assert_that(commands, has_length(2)) for cmd in queue._peek_queue('runtime-1'): assert_that(cmd.state(), is_(State.STARTED)) commands = queue.get_queued_commands('runtime-1') assert_that(commands, has_length(0))
def test_command_json(self): command = Command('command-1') result = json.loads(json.dumps(command, cls=CommandEncoder)) assert_that(result['name'], command.name) assert_that(result['seq_id'], command.seq_id) assert_that(len(result), is_(2))
def test_command_dict(self): command = Command('command-1') result = command.to_dict() assert_that(result['name'], command.name) assert_that(result['seq_id'], command.seq_id) assert_that(len(result), is_(2))
def test_command_timeout(self): command = Command('command-1') assert_that(command.state(), is_(State.QUEUED)) command._started_at = time.time() - 31 assert_that(command.state(), is_(State.TIMEOUT))
def test_command_fail(self): command = Command('command-1') assert_that(command.state(), is_(State.QUEUED)) command.fail() assert_that(command.state(), is_(State.FAIL))
def test_set_result_no_command(self): queue = MemoryCommandQueue() queue.add_command('runtime-1', Command('test')) queue.set_command_result('runtime-1', 2, True, 100)
def test_set_result_no_runtime(self): queue = MemoryCommandQueue() command = Command('test') queue.add_command('runtime-1', command) queue.set_command_result('runtime-2', 1, True, 100)