1# coding=utf-8 2""" 3Copyright 2013 LinkedIn Corp. All rights reserved. 4 5Licensed under the Apache License, Version 2.0 (the "License"); 6you may not use this file except in compliance with the License. 7You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11Unless required by applicable law or agreed to in writing, software 12distributed under the License is distributed on an "AS IS" BASIS, 13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14See the License for the specific language governing permissions and 15limitations under the License. 16""" 17 18import os 19import sys 20# add the path of ~/naarad/src; the testing py is under ~/naarad/test 21sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'src'))) 22 23from naarad.run_steps.run_step import Run_Step 24from naarad.run_steps.local_cmd import Local_Cmd 25import naarad.utils 26import naarad.naarad_constants as CONSTANTS 27 28local_cmd_obj = None 29 30 31def setup_module(): 32 global local_cmd_obj 33 run_cmd = "sleep 10" 34 run_rank = 1 35 run_type = CONSTANTS.RUN_TYPE_WORKLOAD 36 run_order = CONSTANTS.PRE_ANALYSIS_RUN 37 call_type = 'local' 38 local_cmd_obj = Local_Cmd(run_type, run_cmd, call_type, run_order, run_rank) 39 40 41def test_run_local_cmd(): 42 """ 43 Test whether local command works as expected 44 :return: None 45 """ 46 global local_cmd_obj 47 local_cmd_obj.run() 48 ts_diff = naarad.utils.convert_to_unixts(local_cmd_obj.ts_end) - naarad.utils.convert_to_unixts(local_cmd_obj.ts_start) 49 ts_diff /= 1000 50 assert ts_diff == 10.0 51 52 53def test_run_local_cmd_with_kill(): 54 """ 55 Test whether local command works as expected when kill is specified 56 :return: None 57 """ 58 global local_cmd_obj 59 local_cmd_obj.kill_after_seconds = 5 60 local_cmd_obj.run() 61 ts_diff = naarad.utils.convert_to_unixts(local_cmd_obj.ts_end) - naarad.utils.convert_to_unixts(local_cmd_obj.ts_start) 62 ts_diff /= 1000 63 assert ts_diff == 5.0 64