s4 messaging tests: Tests for smbcontrol sleep command
authorGary Lockyer <gary@catalyst.net.nz>
Wed, 5 Dec 2018 01:50:22 +0000 (14:50 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 19 Dec 2018 03:52:59 +0000 (04:52 +0100)
Add a sleep command that pauses the target process for the specified
number seconds

This command is only enabled on developer and self test builds.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/blackbox/smbcontrol_process.py
selftest/knownfail.d/smbcontrol [new file with mode: 0644]

index 342bace84221a0d37a041da1110c381212f41043..4313c6faef3278a1a3dd096c2f981c67fddad1b7 100644 (file)
@@ -20,6 +20,7 @@
 # tests.
 #
 from __future__ import print_function
+import time
 from samba.tests import BlackboxTestCase, BlackboxProcessError
 from samba.messaging import Messaging
 
@@ -83,3 +84,41 @@ class SmbcontrolProcessBlockboxTests(BlackboxTestCase):
             self.fail("Could ping rpc_server process")
         except BlackboxProcessError as e:
             pass
+
+    def test_sleep(self):
+        SLEEP = "sleep"  # smbcontrol sleep command
+        DURATION = 5     # duration to sleep server for
+        DELTA = 1        # permitted error for the sleep duration
+
+        pid = self.get_process("rpc_server")
+        #
+        # Ensure we can ping the process before getting it to sleep
+        #
+        try:
+            self.check_run("%s %s %s" % (COMMAND, pid, PING),
+                           msg="trying to ping rpc_server")
+        except BlackboxProcessError as e:
+            self.fail("Unable to ping rpc_server process")
+
+        #
+        # Now ask it to sleep
+        #
+        start = time.time()
+        try:
+            self.check_run("%s %s %s %s" % (COMMAND, pid, SLEEP, DURATION),
+                           msg="putting rpc_server to sleep for %d" % DURATION)
+        except BlackboxProcessError as e:
+            print(e)
+            self.fail("Failed to get rpc_server to sleep for %d" % DURATION)
+
+        #
+        # The process should be sleeping and not respond until it wakes
+        #
+        try:
+            self.check_run("%s %s %s" % (COMMAND, pid, PING),
+                           msg="trying to ping rpc_server")
+            end = time.time()
+            duration = end - start
+            self.assertGreater(duration + DELTA, DURATION)
+        except BlackboxProcessError as e:
+            self.fail("Unable to ping rpc_server process")
diff --git a/selftest/knownfail.d/smbcontrol b/selftest/knownfail.d/smbcontrol
new file mode 100644 (file)
index 0000000..8d92d92
--- /dev/null
@@ -0,0 +1,2 @@
+^samba.tests.blackbox.smbcontrol_process.samba.tests.blackbox.smbcontrol_process.SmbcontrolProcessBlockboxTests.test_sleep\(preforkrestartdc:local\)
+^samba.tests.blackbox.smbcontrol_process.python3.samba.tests.blackbox.smbcontrol_process.SmbcontrolProcessBlockboxTests.test_sleep\(preforkrestartdc:local\)