Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/gold_tests/pluginTest/lua/gold/lifecycle.gold
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions tests/gold_tests/pluginTest/lua/gold/lifecycle.stderr.gold

This file was deleted.

6 changes: 6 additions & 0 deletions tests/gold_tests/pluginTest/lua/gold/metrics.gold
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions tests/gold_tests/pluginTest/lua/gold/metrics.stdout.gold

This file was deleted.

32 changes: 32 additions & 0 deletions tests/gold_tests/pluginTest/lua/lifecycle_stats.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 15 additions & 14 deletions tests/gold_tests/pluginTest/lua/lua_states_stats.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this text being grabbed in the Streams object. We should have examples test using later for a given test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifecycle_stats.sh script needs to read the stderr output from traffic_manager. I tried reading it from the stderr file in _output for the ts process, but the output the script needs gets buffered in memory. In any case, not good to hardcode the sandbox tree structure into tests.

)
# 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": ""}
Expand All @@ -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,
Expand All @@ -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
31 changes: 31 additions & 0 deletions tests/gold_tests/pluginTest/lua/metrics.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to just get all the metrics by explicitly mention their names? can occur that we get more metrics than the ones you defined in the metrics.gold? probably not as this is isolated in this test(worth asking). In any case if you request for a record that does not exist you will get an error out of the traffic_ctl (in case you request traffic_ctl metric get a b c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't know enough about metrics generally to know if there is a risk that other metrics would appear in the output in a pseudo-random fashion. I did not see that in my testing.

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