def test_two_commands_uptime_whoami( buffer_connection, command_output_and_expected_result_uptime_whoami): from moler.cmd.unix.uptime import Uptime from moler.cmd.unix.whoami import Whoami command_output, expected_result = command_output_and_expected_result_uptime_whoami uptime_cmd = Uptime(connection=buffer_connection.moler_connection) whoami_cmd = Whoami(connection=buffer_connection.moler_connection) uptime_cmd.start(timeout=2) time.sleep(0.005) whoami_cmd.start(timeout=2) time.sleep(0.05) assert CommandScheduler.is_waiting_for_execution( connection_observer=whoami_cmd) is True buffer_connection.moler_connection.data_received( command_output[0].encode("utf-8"), datetime.datetime.now()) time.sleep(0.2) buffer_connection.moler_connection.data_received( command_output[1].encode("utf-8"), datetime.datetime.now()) assert EventAwaiter.wait_for_all(timeout=2, events=[uptime_cmd, whoami_cmd]) is True ret_uptime = uptime_cmd.result() ret_whoami = whoami_cmd.result() assert ret_uptime == expected_result[0] assert ret_whoami == expected_result[1] assert CommandScheduler.is_waiting_for_execution( connection_observer=whoami_cmd) is False
def test_two_commands_uptime(buffer_connection, command_output_and_expected_result_uptime): from moler.cmd.unix.uptime import Uptime command_output, expected_result = command_output_and_expected_result_uptime uptime1_cmd = Uptime(connection=buffer_connection.moler_connection, prompt="host:.*#") uptime2_cmd = Uptime(connection=buffer_connection.moler_connection, prompt="host:.*#") uptime1_cmd.start(timeout=2) uptime2_cmd.start(timeout=2) time.sleep(0.05) buffer_connection.moler_connection.data_received( command_output[0].encode("utf-8"), datetime.datetime.now()) time.sleep(0.2) buffer_connection.moler_connection.data_received( command_output[1].encode("utf-8"), datetime.datetime.now()) assert EventAwaiter.wait_for_all(timeout=2, events=(uptime1_cmd, uptime2_cmd)) is True uptime1_ret = uptime1_cmd.result() uptime2_ret = uptime2_cmd.result() assert uptime1_ret == expected_result[0] assert uptime2_ret == expected_result[1]