def test_get_execution_duration_from_global_result_json_retrieves_float_duration( ): """Test when execution duration is a float.""" global_result_json = {"execution_duration": "2.7s"} duration = utility.get_execution_duration_from_global_result_json( global_result_json) assert duration == 2.7
def test_get_execution_duration_from_global_result_json_retrieves_zero_duration( ): """Test when execution duration is zero.""" global_result_json = {"execution_duration": "0s"} duration = utility.get_execution_duration_from_global_result_json( global_result_json) assert duration == 0
def test_http_request_release_timing(http_test_server_fixture, qps_parameterization_fixture, duration_parameterization_fixture): """Test latency-sample-, query- and reply- counts in various configurations.""" for concurrency in [1, 2]: parsed_json, _ = http_test_server_fixture.runNighthawkClient([ http_test_server_fixture.getTestServerRootUri(), "--duration", str(duration_parameterization_fixture), "--rps", str(qps_parameterization_fixture), "--concurrency", str(concurrency) ]) global_histograms = http_test_server_fixture.getNighthawkGlobalHistogramsbyIdFromJson( parsed_json) counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json) global_result = http_test_server_fixture.getGlobalResults(parsed_json) actual_duration = utility.get_execution_duration_from_global_result_json(global_result) # Ensure Nighthawk managed to execute for at least some time. assert actual_duration >= 1 # The actual duration is a float, flooring if here allows us to use # the GreaterEqual matchers below. total_requests = qps_parameterization_fixture * concurrency * math.floor(actual_duration) asserts.assertGreaterEqual( int(global_histograms["benchmark_http_client.request_to_response"]["count"]), total_requests) asserts.assertGreaterEqual( int(global_histograms["benchmark_http_client.queue_to_connect"]["count"]), total_requests) asserts.assertGreaterEqual(int(global_histograms["benchmark_http_client.latency_2xx"]["count"]), total_requests) asserts.assertCounterGreaterEqual(counters, "benchmark.http_2xx", (total_requests)) # Give system resources some time to recover after the last execution. time.sleep(2)
def test_get_execution_duration_from_global_result_json_retrieves_duration(): """Test for the successful case.""" global_result_json = {"execution_duration": "5s"} duration = utility.get_execution_duration_from_global_result_json( global_result_json) assert duration == 5
def test_get_execution_duration_from_global_result_json_missing_suffix(): """Test for the failure when execution_duration is missing the 's' suffix.""" global_result_json = {"execution_duration": "5"} with pytest.raises(utility.Error): utility.get_execution_duration_from_global_result_json( global_result_json)
def test_get_execution_duration_from_global_result_json_missing_duration(): """Test for the failure when execution_duration is missing.""" with pytest.raises(utility.Error): utility.get_execution_duration_from_global_result_json({})