def test_exit_gracefully(self): """Gracefully shoudl run tap command""" args = CliArgs(target='target_one', tap='tap_one') pipelinewise = PipelineWise(args, CONFIG_DIR, VIRTUALENVS_DIR) # Create a test log file, simulating a running tap pipelinewise.tap_run_log_file = 'test-tap-run-dummy.log' Path('{}.running'.format(pipelinewise.tap_run_log_file)).touch() # Graceful exit should return 1 by default with pytest.raises(SystemExit) as pytest_wrapped_e: pipelinewise._exit_gracefully(signal.SIGINT, frame=None) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 1 # Graceful exit should rename log file from running status to terminated assert os.path.isfile('{}.terminated'.format(pipelinewise.tap_run_log_file)) # Delete test log file os.remove('{}.terminated'.format(pipelinewise.tap_run_log_file))
def test_command_stop_tap(self): """Test stop tap command""" args = CliArgs(target='target_one', tap='tap_one') pipelinewise = PipelineWise(args, CONFIG_DIR, VIRTUALENVS_DIR) pipelinewise.tap_run_log_file = 'test-tap-run-dummy.log' Path('{}.running'.format(pipelinewise.tap_run_log_file)).touch() # Tap is not running, pid file not exist, should exit with error with pytest.raises(SystemExit) as pytest_wrapped_e: pipelinewise.stop_tap() assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 1 # Stop tap command should stop all the child processes # 1. Start the pipelinewise mock executable that's running # linux piped dummy tap and target connectors with pidfile.PIDFile(pipelinewise.tap['files']['pidfile']): os.spawnl( os.P_NOWAIT, f'{RESOURCES_DIR}/test_stop_tap/scheduler-mock.sh', 'test_stop_tap/scheduler-mock.sh', ) # Wait 5 seconds making sure the dummy tap is running time.sleep(5) # Send the stop_tap command with pytest.raises(SystemExit): pipelinewise.stop_tap() # Should not have any remaining Pipelinewise related linux process for proc in psutil.process_iter(['cmdline']): full_command = ' '.join(proc.info['cmdline']) if proc.info['cmdline'] else '' assert re.match('scheduler|pipelinewise|tap|target', full_command) is None # Graceful exit should rename log file from running status to terminated assert os.path.isfile('{}.terminated'.format(pipelinewise.tap_run_log_file)) # Delete test log file os.remove('{}.terminated'.format(pipelinewise.tap_run_log_file))