diff --git a/tests/gold_tests/pluginTest/lua/gold/lifecycle.gold b/tests/gold_tests/pluginTest/lua/gold/lifecycle.gold new file mode 100644 index 00000000000..718a4b7cc68 --- /dev/null +++ b/tests/gold_tests/pluginTest/lua/gold/lifecycle.gold @@ -0,0 +1,8 @@ +(global) id: 0 +(global) id: 1 +(global) id: 2 +(global) id: 3 +(remap) id: 0 +(remap) id: 1 +(remap) id: 2 +(remap) id: 3 diff --git a/tests/gold_tests/pluginTest/lua/gold/lifecycle.stderr.gold b/tests/gold_tests/pluginTest/lua/gold/lifecycle.stderr.gold deleted file mode 100644 index 1e4a4f87dfb..00000000000 --- a/tests/gold_tests/pluginTest/lua/gold/lifecycle.stderr.gold +++ /dev/null @@ -1,6 +0,0 @@ -`` -`` ts_lua (remap) id: 0 gc_kb: `` gc_kb_max: `` threads: `` threads_max: `` -`` ts_lua (remap) id: 1 gc_kb: `` gc_kb_max: `` threads: `` threads_max: `` -`` ts_lua (remap) id: 2 gc_kb: `` gc_kb_max: `` threads: `` threads_max: `` -`` ts_lua (remap) id: 3 gc_kb: `` gc_kb_max: `` threads: `` threads_max: `` -`` diff --git a/tests/gold_tests/pluginTest/lua/gold/metrics.gold b/tests/gold_tests/pluginTest/lua/gold/metrics.gold new file mode 100644 index 00000000000..a40413cbead --- /dev/null +++ b/tests/gold_tests/pluginTest/lua/gold/metrics.gold @@ -0,0 +1,6 @@ +plugin.lua.global.states +plugin.lua.global.gc_bytes +plugin.lua.global.threads +plugin.lua.remap.states +plugin.lua.remap.gc_bytes +plugin.lua.remap.threads diff --git a/tests/gold_tests/pluginTest/lua/gold/metrics.stdout.gold b/tests/gold_tests/pluginTest/lua/gold/metrics.stdout.gold deleted file mode 100644 index 4c1362bea13..00000000000 --- a/tests/gold_tests/pluginTest/lua/gold/metrics.stdout.gold +++ /dev/null @@ -1,6 +0,0 @@ -plugin.lua.global.states `` -plugin.lua.global.gc_bytes `` -plugin.lua.global.threads `` -plugin.lua.remap.states `` -plugin.lua.remap.gc_bytes `` -plugin.lua.remap.threads `` diff --git a/tests/gold_tests/pluginTest/lua/lifecycle_stats.sh b/tests/gold_tests/pluginTest/lua/lifecycle_stats.sh new file mode 100755 index 00000000000..764a1015d74 --- /dev/null +++ b/tests/gold_tests/pluginTest/lua/lifecycle_stats.sh @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +traffic_ctl plugin msg ts_lua print_stats +N=60 +while (( N > 0 )) +do + sleep 1 + rm -f lifecycle.out + grep -F ' ts_lua ' ts.stderr.txt | \ + sed -e 's/^.* ts_lua //' -e 's/ gc_kb:.*gc_kb_max:.*threads:.*threads_max:.*$//' > lifecycle.out + if diff lifecycle.out ${AUTEST_TEST_DIR}/gold/lifecycle.gold > /dev/null + then + exit 0 + fi + let N=N-1 +done +echo TIMEOUT +exit 1 diff --git a/tests/gold_tests/pluginTest/lua/lua_states_stats.test.py b/tests/gold_tests/pluginTest/lua/lua_states_stats.test.py index 5f0083adf79..47dc09b6b01 100644 --- a/tests/gold_tests/pluginTest/lua/lua_states_stats.test.py +++ b/tests/gold_tests/pluginTest/lua/lua_states_stats.test.py @@ -23,16 +23,25 @@ Test.SkipUnless( Condition.PluginExists('tslua.so'), ) -Test.SkipIf(Condition.true("Test cannot deterministically wait until the stats appear")) Test.ContinueOnFail = True # Define default ATS server = Test.MakeOriginServer("server") -ts = Test.MakeATSProcess("ts", command="traffic_manager", select_ports=True) +# It is necessary to redirect stderr to a file so it will be available for examination by a test run. +ts = Test.MakeATSProcess( + "ts", command="traffic_manager 2> " + Test.RunDirectory + "/ts.stderr.txt", select_ports=True +) +# For unknown reasons, traffic_manager returns 2 instead of 0 on exit with stderr redirect here. +ts.ReturnCode = 2 Test.testName = "Lua states and stats" +Test.Setup.Copy("hello.lua") +Test.Setup.Copy("global.lua") +Test.Setup.Copy("metrics.sh") +Test.Setup.Copy("lifecycle_stats.sh") + # test to ensure origin server works request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""} @@ -45,10 +54,10 @@ ts.Disk.remap_config.AddLines({ 'map / http://127.0.0.1:{}/'.format(server.Variables.Port), 'map http://hello http://127.0.0.1:{}/'.format(server.Variables.Port) + - ' @plugin=tslua.so @pparam={}/hello.lua'.format(Test.TestDirectory) + ' @plugin=tslua.so @pparam={}/hello.lua'.format(Test.RunDirectory) }) -ts.Disk.plugin_config.AddLine('tslua.so {}/global.lua'.format(Test.TestDirectory)) +ts.Disk.plugin_config.AddLine('tslua.so {}/global.lua'.format(Test.RunDirectory)) ts.Disk.records_config.update({ 'proxy.config.diags.debug.enabled': 1, @@ -67,36 +76,28 @@ ps.Env = ts.Env ps.ReturnCode = 0 ps.Streams.stdout.Content = Testers.ContainsExpression("proxy.config.plugin.lua.max_states: 4", "expected 4 states") -tr.TimeOut = 5 tr.StillRunningAfter = ts # 1 Test - Exercise lua script tr = Test.AddTestRun("Lua hello") ps = tr.Processes.Default # alias ps.Command = curl_and_args + ' http://hello/hello' -ps.TimeOut = 5 ps.ReturnCode = 0 ps.Streams.stderr.Content = Testers.ContainsExpression("Hello, World", "hello world content") -tr.TimeOut = 5 tr.StillRunningAfter = ts # 2 Test - Check for metrics tr = Test.AddTestRun("Check for metrics") -tr.DelayStart = 15 # 5s lag on metrics to update -tr.TimeOut = 5 ps = tr.Processes.Default # alias -ps.Env = ts.Env -ps.Command = "traffic_ctl metric match lua" +ps.Command = "bash -c ./metrics.sh" ps.Env = ts.Env ps.ReturnCode = 0 -ps.Streams.stdout = "gold/metrics.stdout.gold" tr.StillRunningAfter = ts # 3 Test - Check for developer lifecycle stats tr = Test.AddTestRun("Check for lifecycle stats") ps = tr.Processes.Default # alias -ps.Command = "traffic_ctl plugin msg ts_lua print_stats" +ps.Command = "bash -c ./lifecycle_stats.sh" ps.Env = ts.Env ps.ReturnCode = 0 -ts.Streams.stderr = "gold/lifecycle.stderr.gold" tr.StillRunningAfter = ts diff --git a/tests/gold_tests/pluginTest/lua/metrics.sh b/tests/gold_tests/pluginTest/lua/metrics.sh new file mode 100755 index 00000000000..6aec5bc03b2 --- /dev/null +++ b/tests/gold_tests/pluginTest/lua/metrics.sh @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +N=60 +while (( N > 0 )) +do + rm -f metrics.out metrics.txt + traffic_ctl metric match lua > metrics.out + sleep 1 + sed 's/ [0-9][0-9]*//' metrics.out > metrics.txt + if diff metrics.txt ${AUTEST_TEST_DIR}/gold/metrics.gold + then + exit 0 + fi + let N=N-1 +done +echo TIMEOUT +exit 1