Commit 4b564bbe authored by Jérome Perrin's avatar Jérome Perrin

software/theia/test: simplify a test by using self.addCleanup

parent 28c25f43
...@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase): ...@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase):
# Start a theia shell that inherits the environment of the theia process # Start a theia shell that inherits the environment of the theia process
# This simulates the environment of a shell launched from the browser application # This simulates the environment of a shell launched from the browser application
theia_shell_process = pexpect.spawnu('{}/bin/theia-shell'.format(self.getPath()), env=theia_env) theia_shell_process = pexpect.spawnu('{}/bin/theia-shell'.format(self.getPath()), env=theia_env)
try: self.addCleanup(theia_shell_process.wait)
theia_shell_process.expect_exact('Standalone SlapOS for computer `slaprunner` activated') self.addCleanup(theia_shell_process.terminate)
# Launch slapos node software from theia shell theia_shell_process.expect_exact('Standalone SlapOS for computer `slaprunner` activated')
theia_shell_process.sendline('slapos node software')
theia_shell_process.expect('Installing software release %s' % self.dummy_software_path) # Launch slapos node software from theia shell
theia_shell_process.expect('Finished software releases.') theia_shell_process.sendline('slapos node software')
theia_shell_process.expect('Installing software release %s' % self.dummy_software_path)
# Get the theia shell environment theia_shell_process.expect('Finished software releases.')
with open(env_json_path) as f:
theia_shell_env = json.load(f) # Get the theia shell environment
with open(env_json_path) as f:
# Remove the env.json file to later be sure that a new one has been generated theia_shell_env = json.load(f)
os.remove(env_json_path)
# Remove the env.json file to later be sure that a new one has been generated
# Launch slapos node software service from the embedded supervisord. os.remove(env_json_path)
# Note that we have two services, slapos-node-software and slapos-node-software-all
# The later uses --all which is what we want to use here, because the software # Launch slapos node software service from the embedded supervisord.
# is already installed and we want to install it again, this time from supervisor # Note that we have two services, slapos-node-software and slapos-node-software-all
embedded_run_path = self.getPath('srv', 'runner', 'var', 'run') # The later uses --all which is what we want to use here, because the software
embedded_supervisord_socket_path = _getSupervisordSocketPath(embedded_run_path, self.logger) # is already installed and we want to install it again, this time from supervisor
with getSupervisorRPC(embedded_supervisord_socket_path) as embedded_supervisor: embedded_run_path = self.getPath('srv', 'runner', 'var', 'run')
previous_stop_time = embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] embedded_supervisord_socket_path = _getSupervisordSocketPath(embedded_run_path, self.logger)
embedded_supervisor.startProcess('slapos-node-software-all') with getSupervisorRPC(embedded_supervisord_socket_path) as embedded_supervisor:
for _retries in range(20): previous_stop_time = embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop']
time.sleep(1) embedded_supervisor.startProcess('slapos-node-software-all')
if embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] != previous_stop_time: for _retries in range(20):
break time.sleep(1)
else: if embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] != previous_stop_time:
self.fail("the supervisord service 'slapos-node-software-all' takes too long to finish") break
else:
# Get the supervisord environment self.fail("the supervisord service 'slapos-node-software-all' takes too long to finish")
with open(env_json_path) as f:
supervisord_env = json.load(f) # Get the supervisord environment
with open(env_json_path) as f:
# Compare relevant variables from both environments supervisord_env = json.load(f)
self.maxDiff = None
self.assertEqual(theia_shell_env['PATH'].split(':'), supervisord_env['PATH'].split(':')) # Compare relevant variables from both environments
self.assertEqual(theia_shell_env['SLAPOS_CONFIGURATION'], supervisord_env['SLAPOS_CONFIGURATION']) self.maxDiff = None
self.assertEqual(theia_shell_env['SLAPOS_CLIENT_CONFIGURATION'], supervisord_env['SLAPOS_CLIENT_CONFIGURATION']) self.assertEqual(theia_shell_env['PATH'].split(':'), supervisord_env['PATH'].split(':'))
self.assertEqual(theia_shell_env['HOME'], supervisord_env['HOME']) self.assertEqual(theia_shell_env['SLAPOS_CONFIGURATION'], supervisord_env['SLAPOS_CONFIGURATION'])
self.assertEqual(theia_shell_env['SLAPOS_CLIENT_CONFIGURATION'], supervisord_env['SLAPOS_CLIENT_CONFIGURATION'])
finally: self.assertEqual(theia_shell_env['HOME'], supervisord_env['HOME'])
# Cleanup the theia shell process
theia_shell_process.terminate()
theia_shell_process.wait()
class ResilientTheiaMixin(object): class ResilientTheiaMixin(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment