aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-03-29 11:04:46 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-04-15 11:33:04 -0400
commit5e3eb985367c0d945b45a2e07b01e3fc37e7e18e (patch)
treee4c061c80a27fac259acff2f8e5d11cb3fee0544
parent0fac82c90d6493aef21ef84c3132416ba2c5e9fb (diff)
downloadsos-5e3eb985367c0d945b45a2e07b01e3fc37e7e18e.tar.gz
[tests] Add a StageTwo timeout test
Adds a test to ensure our timeout control is working properly. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--tests/report_tests/timeout_tests.py44
-rw-r--r--tests/test_data/fake_plugins/timeout_test.py21
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/report_tests/timeout_tests.py b/tests/report_tests/timeout_tests.py
new file mode 100644
index 00000000..58678644
--- /dev/null
+++ b/tests/report_tests/timeout_tests.py
@@ -0,0 +1,44 @@
+# This file is part of the sos project: https://github.com/sosreport/sos
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# version 2 of the GNU General Public License.
+#
+# See the LICENSE file in the source distribution for further information.
+
+from sos_tests import StageTwoReportTest
+
+
+class PluginTimeoutTest(StageTwoReportTest):
+ """Test that whole plugin timeout control is working
+
+ :avocado: tags=stagetwo
+ """
+
+ install_plugins = ['timeout_test']
+ sos_cmd = '-o timeout_test -vvv --plugin-timeout=10'
+
+ def test_plugin_timed_out(self):
+ self.assertSosLogNotContains('collected plugin \'timeout_test\' in')
+ self.assertSosUILogContains('Plugin timeout_test timed out')
+
+ def test_no_output_collected(self):
+ self.assertFileNotExists('sos_commands/timeout_test/echo_out')
+
+
+class NativeCmdTimeoutTest(StageTwoReportTest):
+ """Test that the native timeout control for the plugin API is working
+
+ :avocado: tags=stagetwo
+ """
+
+ install_plugins = ['timeout_test']
+ sos_cmd = '-o timeout_test -vvv'
+
+ def test_plugin_completed(self):
+ self.assertSosLogContains('collected plugin \'timeout_test\' in')
+ self.assertFileCollected('sos_commands/timeout_test/echo_good')
+
+ def test_command_timed_out(self):
+ self.assertSosLogContains(r"\[plugin:timeout_test\] command 'sleep 30' timed out after 10s")
+ self.assertFileCollected('sos_commands/timeout_test/sleep_30')
diff --git a/tests/test_data/fake_plugins/timeout_test.py b/tests/test_data/fake_plugins/timeout_test.py
new file mode 100644
index 00000000..3a027c42
--- /dev/null
+++ b/tests/test_data/fake_plugins/timeout_test.py
@@ -0,0 +1,21 @@
+# This file is part of the sos project: https://github.com/sosreport/sos
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# version 2 of the GNU General Public License.
+#
+# See the LICENSE file in the source distribution for further information.
+
+from sos.report.plugins import Plugin, IndependentPlugin
+
+
+class TimeoutTest(Plugin, IndependentPlugin):
+
+ plugin_name = 'timeout_test'
+ short_desc = 'Tests timeout functionality in test suite'
+
+
+ def setup(self):
+ self.add_cmd_output('sleep 15')
+ self.add_cmd_output('echo I slept great', suggest_filename='echo_good')
+ self.add_cmd_output('sleep 30', timeout=10)