This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 95873c9ac3c20445311320aec737934f90ab9192
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Sat Jan 13 00:34:06 2018 +0200
Add tests for sanlock lockfile
Add test for sanlock lockfile functionality:
- Only one instance can be started
- Being able to start the daemon after killing it
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/daemon_test.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/tests/daemon_test.py b/tests/daemon_test.py
index 352a065..1c304ae 100644
--- a/tests/daemon_test.py
+++ b/tests/daemon_test.py
@@ -5,6 +5,7 @@ Test sanlock client operations.
import errno
import io
import os
+import signal
import socket
import struct
import subprocess
@@ -60,6 +61,19 @@ def wait_for_socket(timeout):
s.close()
+def wait_for_termination(p, timeout):
+ """
+ Wait until process terminates, or timeout expires.
+ """
+ deadline = time.time() + timeout
+ while True:
+ if p.poll() is not None:
+ return
+ if time.time() > deadline:
+ raise TimeoutExpired
+ time.sleep(0.05)
+
+
@pytest.fixture
def sanlock_daemon():
p = start_sanlock_daemon()
@@ -71,6 +85,29 @@ def sanlock_daemon():
p.wait()
+def test_single_instance(sanlock_daemon):
+ # Starting another instance while the daemon must fail.
+ p = start_sanlock_daemon()
+ try:
+ wait_for_termination(p, 1.0)
+ except TimeoutExpired:
+ p.kill()
+ p.wait()
+ assert p.returncode == 255 # exit code -1
+
+
+def test_start_after_kill():
+ # After killing the daemon, next instance should be able to start.
+ for i in range(5):
+ p = start_sanlock_daemon()
+ try:
+ wait_for_socket(0.5)
+ finally:
+ p.kill()
+ p.wait()
+ assert p.returncode == -signal.SIGKILL
+
+
def test_init_lockspace(tmpdir, sanlock_daemon):
path = tmpdir.join("lockspace")
with io.open(str(path), "wb") as f:
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.