D-Bus testing: fix TestFileNotify

The test assumed that it can rename the main syncevo-dbus-server
executable to trigger the file watch mechanism. That's not correct:
- It might be the system's /usr/libexec/syncevo-dbus-server,
  which a normal user cannot rename.
- The binary might be also active in some other, parallel tests.
  Renaming it interferes with those other tests.

The latter happened in the nightly testing: HTTP server tests with
a long-running syncevo-dbus-server failed because the daemon terminated
during the tests.
This commit is contained in:
Patrick Ohly 2014-04-10 06:10:39 -07:00
parent 58fa67f76d
commit 51d21e8127
1 changed files with 25 additions and 1 deletions

View File

@ -5211,8 +5211,32 @@ class TestFileNotify(unittest.TestCase, DBusUtil):
if os.path.isfile(self.serverexe + ".bak"):
os.rename(self.serverexe + ".bak", self.serverexe)
def which(self, program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
for path in os.environ['PATH'].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def run(self, result):
self.runTest(result)
# Ensure that we use a private copy of syncevo-dbus-server, for two reasons:
# - when using the installed version, we might not be able to rename it.
# - when other tests run concurrently, they too would see the modification and shut down.
tmppath = os.path.abspath('TestFileNotifyDir')
oldpath = os.environ['PATH']
try:
os.makedirs(tmppath)
shutil.copy(self.which('syncevo-dbus-server'), tmppath)
os.environ['PATH'] = '%s:%s' % (tmppath, oldpath)
self.runTest(result)
finally:
os.environ['PATH'] = oldpath
if os.path.exists(tmppath):
shutil.rmtree(tmppath)
def modifyServerFile(self):
"""rename server executable to trigger shutdown"""