Module: check_mk
Branch: master
Commit: 212d25e90cca96afdd0025b847e2af2a7f35014a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=212d25e90cca96…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Mon Apr 16 10:33:25 2018 +0200
Win-agent integration tests: retry 20 min if VM occupied
Retry obtaining test lock 20 times at intervals of 60s if the VM running
the tests is occupied. This has become essential as at least 1.5.0 and
master builds are sharing the same VM so another build is likely to be
running on the same VM much more often than before.
---
agents/windows/it/conftest.py | 12 +++++++++---
agents/windows/it/lock.py | 20 +++++++++++++-------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/agents/windows/it/conftest.py b/agents/windows/it/conftest.py
index e306010..83f73e5 100644
--- a/agents/windows/it/conftest.py
+++ b/agents/windows/it/conftest.py
@@ -18,19 +18,25 @@ def lock_cmd(subcmd):
]
-def acquire_lock():
+def lock_operation(command):
+ # Copy essential sources always to remote host. This is necessary as
+ # another test executor might have removed the files meanwhile.
files = [os.path.join(localdir, f) for f in ['lock.py',
'remote.py']]
cmds = [[
'scp',
sshopts,
] + files + ['%s@%s:%s' % (remoteuser, remote_ip, remotedir)],
- lock_cmd('acquire')]
+ lock_cmd(command)]
for cmd in cmds:
assert_subprocess(cmd)
+def acquire_lock():
+ lock_operation('acquire')
+
+
def release_lock():
- assert_subprocess(lock_cmd('release'))
+ lock_operation('release')
def scp_agent_exe():
diff --git a/agents/windows/it/lock.py b/agents/windows/it/lock.py
index 0d5d647..ac1a5d8 100644
--- a/agents/windows/it/lock.py
+++ b/agents/windows/it/lock.py
@@ -6,6 +6,7 @@
from contextlib import contextmanager
import os
import sys
+import time
from win32api import GetLastError
from win32event import CreateMutex, ReleaseMutex
from winerror import ERROR_ALREADY_EXISTS
@@ -14,7 +15,7 @@ from remote import remotedir
lockname = os.path.join(remotedir, 'test.lock')
mutexname = '__test_lock__'
-
+retry_count = 20
@contextmanager
def synchronized():
@@ -31,12 +32,17 @@ def synchronized():
def acquire():
- with synchronized():
- if os.path.exists(lockname):
- sys.stderr.write(
- 'Lock file exists. Is another test process running?')
- sys.exit(1)
- open(lockname, 'w').close()
+ for i in range(retry_count):
+ with synchronized():
+ if not os.path.exists(lockname):
+ open(lockname, 'w').close()
+ return
+ sys.stderr.write('Lock file exists. Waiting 60s...')
+ time.sleep(60)
+
+ sys.stderr.write('Lock file still exists after waiting %d minutes. '
+ 'Another test process hung?')
+ sys.exit(1)
def release():