From 5937d758b549644dc1a634f50b3f1dd5c7f47a45 Mon Sep 17 00:00:00 2001 From: Simon Crowle <sgc@it-innovation.soton.ac.uk> Date: Tue, 3 Apr 2018 13:49:46 +0100 Subject: [PATCH] Adds tests for averaging average state times per sample period Seeds random number generation for predictable results --- clmctest/monitoring/test_simresults.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/clmctest/monitoring/test_simresults.py b/clmctest/monitoring/test_simresults.py index 8953a58..a058d4d 100644 --- a/clmctest/monitoring/test_simresults.py +++ b/clmctest/monitoring/test_simresults.py @@ -2,6 +2,7 @@ import pytest import time +import random class TestSimulation(object): @@ -10,11 +11,17 @@ class TestSimulation(object): """ @pytest.fixture(scope='class') def run_simulator( self, simulator ): + + random.seed( 0 ) # Seed random function so we can reliably test for average queries + + print( "Running simulation, please wait..." ) simulator.run( 3600 ) print( "Waiting for INFLUX to finish receiving simulation data..." ) time.sleep( 10 ) # wait for data to finish arriving at the INFLUX database + print( "... simulation data fixture finished" ) + @pytest.mark.parametrize("query, expected_result", [ ('SELECT count(*) FROM "CLMCMetrics"."autogen"."cpu_usage"', {"time": "1970-01-01T00:00:00Z", "count_cpu_active_time": 7200, "count_cpu_idle_time": 7200, "count_cpu_usage": 7200}), @@ -26,12 +33,25 @@ class TestSimulation(object): {"time": "1970-01-01T00:00:00Z", "count_RX_BYTES_PORT_M": 7200, "count_TX_BYTES_PORT_M": 7200}), ('SELECT count(*) FROM "CLMCMetrics"."autogen"."vm_res_alloc"', {"time": "1970-01-01T00:00:00Z", "count_cpu": 12, "count_memory": 12, "count_storage": 12}), - + + # Media component state tests ('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'', {"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}), ('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'', {"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}), + + ('SELECT mean(avg_stopped) as "avg_stopped" FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE avg_stopped <>0', + {"time" : "1970-01-01T00:00:00Z", "avg_stopped" : 0.9311386970408875}), + ('SELECT mean(avg_starting) as "avg_starting" FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE avg_starting <>0', + {"time" : "1970-01-01T00:00:00Z", "avg_starting" : 1.4332962039049266}), + ('SELECT mean(avg_running) as "avg_running" FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE avg_running <>0', + {"time" : "1970-01-01T00:00:00Z", "avg_running" : 0.9999273119631822}), + ('SELECT mean(avg_stopping) as "avg_stopping" FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE avg_stopping <>0', + {"time" : "1970-01-01T00:00:00Z", "avg_stopping" : 1.1135062967253757}), + ('SELECT mean(avg_stopped) as "avg_stopped" FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE avg_stopped <>0', + {"time" : "1970-01-01T00:00:00Z", "avg_stopped" : 0.9311386970408875}) ]) + def test_simulation( self, run_simulator, influx_db, query, expected_result ): """ This is the entry point of the test. This method will be found and executed when the module is ran using pytest -- GitLab