Skip to content

Commit 086501c

Browse files
authored
Make autest ts shutdown tests more reliable (#9391)
This is a second iteration to further improve some of the autests that exercise ATS shutting down during test execution. See #9372 for the previous patch. The previous update improved reliability, but still had a race condition between autest recognizing ATS process shutdown and ATS writing the expected error log. If it detected the ts process ending before the log was written, the autest would fail because the framework thought the process ended before the Ready condition was satisfied. This patch addresses this by using a separate process to wait upon the log entry instead of making the ts Ready condition the content of the log file.
1 parent caf0059 commit 086501c

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

tests/gold_tests/remap/remap_load_empty_failure.test.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@
2424
ts.Disk.remap_config.AddLine(f"") # empty file
2525
ts.Disk.records_config.update({'proxy.config.url_remap.min_rules_required': 1})
2626
ts.ReturnCode = 33 # expect to Emergency fail due to empty "remap.config".
27-
ts.Ready = When.FileContains(ts.Disk.diags_log.Name, "remap.config failed to load")
27+
ts.Ready = 0
2828

2929
tr = Test.AddTestRun("test")
30+
31+
# We have to wait upon TS to emit the expected log message, but it cannot be
32+
# the ts Ready criteria because autest might detect the process going away
33+
# before it detects the log message. So we add a separate process that waits
34+
# upon the log message.
35+
watcher = Test.Processes.Process("watcher")
36+
watcher.Command = "sleep 1"
37+
watcher.Ready = When.FileContains(ts.Disk.diags_log.Name, "remap.config failed to load")
38+
watcher.StartBefore(ts)
39+
3040
tr.Processes.Default.Command = "echo howdy"
3141
tr.TimeOut = 5
32-
tr.Processes.Default.StartBefore(ts)
42+
tr.Processes.Default.StartBefore(watcher)

tests/gold_tests/shutdown/emergency.test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@
4040
# Load plugin
4141
Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'emergency_shutdown.so'), ts)
4242

43-
# www.example.com Host
4443
tr = Test.AddTestRun()
44+
45+
# We have to wait upon TS to emit the expected log message, but it cannot be
46+
# the ts Ready criteria because autest might detect the process going away
47+
# before it detects the log message. So we add a separate process that waits
48+
# upon the log message.
49+
watcher = Test.Processes.Process("watcher")
50+
watcher.Command = "sleep 1"
51+
watcher.Ready = When.FileContains(ts.Disk.diags_log.Name, "testing emergency shutdown")
52+
watcher.StartBefore(ts)
53+
4554
tr.Processes.Default.Command = 'printf "Emergency Shutdown Test"'
4655
tr.Processes.Default.ReturnCode = 0
47-
tr.Processes.Default.StartBefore(ts)
48-
tr.Timeout = 5
56+
tr.Processes.Default.StartBefore(watcher)
4957

58+
tr.Timeout = 5
5059
ts.ReturnCode = 33
51-
ts.Ready = When.FileContains(ts.Disk.traffic_out.Name, "testing emergency shutdown")
60+
ts.Ready = 0
5261
ts.Disk.traffic_out.Content = Testers.ExcludesExpression('failed to shutdown', 'should NOT contain "failed to shutdown"')
5362
ts.Disk.diags_log.Content = Testers.IncludesExpression('testing emergency shutdown', 'should contain "testing emergency shutdown"')

tests/gold_tests/shutdown/fatal.test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@
4040
# Load plugin
4141
Test.PrepareTestPlugin(os.path.join(Test.Variables.AtsTestPluginsDir, 'fatal_shutdown.so'), ts)
4242

43-
# www.example.com Host
4443
tr = Test.AddTestRun()
44+
45+
# We have to wait upon TS to emit the expected log message, but it cannot be
46+
# the ts Ready criteria because autest might detect the process going away
47+
# before it detects the log message. So we add a separate process that waits
48+
# upon the log message.
49+
watcher = Test.Processes.Process("watcher")
50+
watcher.Command = "sleep 1"
51+
watcher.Ready = When.FileContains(ts.Disk.diags_log.Name, "testing fatal shutdown")
52+
watcher.StartBefore(ts)
53+
4554
tr.Processes.Default.Command = 'printf "Fatal Shutdown Test"'
4655
tr.Processes.Default.ReturnCode = 0
47-
tr.Processes.Default.StartBefore(ts)
48-
tr.Timeout = 5
56+
tr.Processes.Default.StartBefore(watcher)
4957

58+
tr.Timeout = 5
5059
ts.ReturnCode = 70
51-
ts.Ready = When.FileContains(ts.Disk.traffic_out.Name, "testing fatal shutdown")
60+
ts.Ready = 0
5261
ts.Disk.traffic_out.Content = Testers.ExcludesExpression('failed to shutdown', 'should NOT contain "failed to shutdown"')
5362
ts.Disk.diags_log.Content = Testers.IncludesExpression('testing fatal shutdown', 'should contain "testing fatal shutdown"')

0 commit comments

Comments
 (0)