Commit 983a0da1 authored by Marco Mariani's avatar Marco Mariani

fixed timing-sensitive tests

parent 2638f574
master alain-message amarisoft boot/offline cliff-cleanup console cygwin-link-local feat/node-secrets feat/nxdbom feat/openapi feat/slapos-computer-partitions-capabilities-wip feat/standalone-service feat_open_order feature/cgroups feature/format-crumbled feature/lsb_release_sle15 feature/manager-cpuset feature/python-pip-sle15.6 feature/software_url_as_path feature/software_url_as_path_old fix/manager_interface fix/slapos-ansible fix/suse-detection fix/verify fixuitestfrontpage for_testrunner_1 hosting_daily_invoice json-api json-api-2022 json-api-slapgrid master-dev message-box proxy schema slapos-override-env testing/branch1 update_cachecontrol_dependency 1.11.0 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.3 1.9.2 1.9.1 1.9.0 1.8.6 1.8.5 1.8.4 1.8.3 1.8.2 1.8.1 1.8.0 1.7.13 1.7.12 1.7.11 1.7.10 1.7.9 1.7.8 1.7.7 1.7.6 1.7.5 1.7.4 1.7.3 1.7.2 1.7.1 1.7.0 1.6.19 1.6.18 1.6.17 1.6.16 1.6.15 1.6.14 1.6.13 1.6.12 1.6.11 1.6.10 1.6.9 1.6.8 1.6.7 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.12 1.5.11 1.5.10 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.28 1.4.27 1.4.26 1.4.25 1.4.24 1.4.23 1.4.22 1.4.21 1.4.20 1.4.19 1.4.17 1.4.16 1.4.15 1.4.14 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.18 1.3.17 1.3.16 1.3.15 1.3.14 1.3.13 1.3.12 1.3.11 1.3.10 1.3.9 1.3.8 1.3.7 1.3.6.3 1.3.6.2 1.3.6.1 1.3.6 1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4.1 1.2.4 1.2.3.1 1.2.3 1.2.2 1.2.1 1.2.0 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 1.0.0 1.0.0rc6 1.0.0rc5 1.0.0rc4 1.0.0rc3 1.0.0-rc1 v1.8.1 master-20240326 master-20180917
No related merge requests found
......@@ -82,7 +82,7 @@ WRAPPER_CONTENT = """#!/bin/sh
touch worked &&
mkdir -p etc/run &&
echo "#!/bin/sh" > etc/run/wrapper &&
echo "while :; do echo "Working\\nWorking\\n" ; sleep 0.1; done" >> etc/run/wrapper &&
echo "while true; do echo Working; sleep 0.1; done" >> etc/run/wrapper &&
chmod 755 etc/run/wrapper
"""
......@@ -91,9 +91,9 @@ mkdir -p etc/service &&
echo "#!/bin/sh" > etc/service/daemon &&
echo "touch launched
if [ -f ./crashed ]; then
while :; do echo "Working\\nWorking\\n" ; sleep 0.1; done
while true; do echo Working; sleep 0.1; done
else
touch ./crashed; echo "Failing\\nFailing\\n"; sleep 1; exit 111;
touch ./crashed; echo Failing; sleep 1; exit 111;
fi" >> etc/service/daemon &&
chmod 755 etc/service/daemon &&
touch worked
......@@ -164,6 +164,26 @@ class BasicMixin:
self.setSlapgrid(develop=develop)
return self.grid.processSoftwareReleaseList()
def assertLogContent(self, log_path, expected, tries=50):
for i in range(tries):
if expected in open(log_path).read():
return
time.sleep(0.1)
self.fail('%r not found in %s' % (expected, log_path))
def assertIsCreated(self, path, tries=50):
for i in range(tries):
if os.path.exists(path):
return
time.sleep(0.1)
self.fail('%s should be created' % path)
def assertIsNotCreated(self, path, tries=50):
for i in range(tries):
if os.path.exists(path):
self.fail('%s should not be created' % path)
time.sleep(0.1)
def tearDown(self):
# XXX: Hardcoded pid, as it is not configurable in slapos
svc = os.path.join(self.instance_root, 'var', 'run', 'supervisord.pid')
......@@ -571,14 +591,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(partition.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
wrapper_log = os.path.join(partition.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.software_root), [partition.software.software_hash])
self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition',
......@@ -613,14 +627,7 @@ chmod 755 etc/run/wrapper
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
tries = 50
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
os.path.getsize(wrapper_log)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition',
......@@ -633,15 +640,7 @@ chmod 755 etc/run/wrapper
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
expected_text = 'Signal handler called with signal 15'
while tries > 0:
tries -= 1
found = expected_text in open(wrapper_log).read()
if found:
break
time.sleep(0.1)
self.assertTrue(found)
self.assertLogContent(wrapper_log, 'Signal handler called with signal 15')
self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition'])
......@@ -680,14 +679,7 @@ chmod 755 etc/run/wrapper
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
tries = 50
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
os.path.getsize(wrapper_log)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.software_root),
[instance.software.software_hash])
self.assertEqual(computer.sequence,
......@@ -705,15 +697,7 @@ exit 1
['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
expected_text = 'Signal handler called with signal 15'
while tries > 0:
tries -= 1
found = expected_text in open(wrapper_log).read()
if found:
break
time.sleep(0.1)
self.assertTrue(found)
self.assertLogContent(wrapper_log, 'Signal handler called with signal 15')
self.assertEqual(computer.sequence,
['getFullComputerInformation',
'softwareInstanceError'])
......@@ -746,14 +730,8 @@ exit 1
['.0_wrapper.log', 'etc', 'buildout.cfg', 'software_release', 'worked'])
self.assertItemsEqual(os.listdir(self.software_root),
[instance.software.software_hash])
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition',
'startedComputerPartition'])
......@@ -821,22 +799,9 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(partition.partition_path),
['.0_daemon.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 200
daemon_log = os.path.join(partition.partition_path, '.0_daemon.log')
while tries > 0:
tries -= 1
if os.path.getsize(daemon_log) > 0:
break
time.sleep(0.1)
time.sleep(0.1)
self.assertIn('Failing', open(daemon_log).read())
tries = 200
while tries > 0:
tries -= 1
if os.path.exists(self.watchdog_banged):
break
time.sleep(0.1)
self.assertTrue(os.path.exists(self.watchdog_banged))
self.assertLogContent(daemon_log, 'Failing')
self.assertIsCreated(self.watchdog_banged)
self.assertIn('daemon', open(self.watchdog_banged).read())
def test_one_failing_daemon_in_run_will_not_bang_with_watchdog(self):
......@@ -860,7 +825,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
mkdir -p etc/run &&
echo "#!/bin/sh" > etc/run/daemon &&
echo "touch launched
touch ./crashed; echo "Failing\\nFailing\\n"; sleep 1; exit 111;
touch ./crashed; echo Failing; sleep 1; exit 111;
" >> etc/run/daemon &&
chmod 755 etc/run/daemon &&
touch worked
......@@ -873,22 +838,9 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(partition.partition_path),
['.0_daemon.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 200
daemon_log = os.path.join(partition.partition_path, '.0_daemon.log')
while tries > 0:
tries -= 1
if os.path.getsize(daemon_log) > 0:
break
time.sleep(0.1)
time.sleep(0.1)
self.assertIn('Failing', open(daemon_log).read())
tries = 200
while tries > 0:
tries -= 1
if os.path.exists(self.watchdog_banged):
break
time.sleep(0.1)
self.assertFalse(os.path.exists(self.watchdog_banged))
self.assertLogContent(daemon_log, 'Failing')
self.assertIsNotCreated(self.watchdog_banged)
def test_watched_by_watchdog_bang(self):
"""
......@@ -1348,14 +1300,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['getFullComputerInformation',
......@@ -1373,16 +1319,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.software_root),
[instance.software.software_hash])
# Assert supervisor stopped process
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
exists = False
while tries > 0:
tries -= 1
if os.path.exists(wrapper_log):
exists = True
break
time.sleep(0.1)
self.assertFalse(exists)
self.assertIsNotCreated(wrapper_log)
self.assertEqual(computer.sequence,
['getFullComputerInformation',
......@@ -1411,16 +1349,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.software_root),
[instance.software.software_hash])
# Assert supervisor stopped process
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
exists = False
while tries > 0:
tries -= 1
if os.path.exists(wrapper_log):
exists = True
break
time.sleep(0.1)
self.assertFalse(exists)
self.assertIsNotCreated(wrapper_log)
self.assertEqual(
computer.sequence,
......@@ -1438,14 +1368,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.software_root), [instance.software.software_hash])
self.assertEqual(computer.sequence,
['getFullComputerInformation',
......@@ -1459,24 +1383,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertIn('Working', open(wrapper_log).read())
self.assertLogContent(wrapper_log, 'Working')
self.assertItemsEqual(os.listdir(self.instance_root), ['0', 'etc', 'var'])
self.assertItemsEqual(os.listdir(instance.partition_path),
['.0_wrapper.log', 'buildout.cfg', 'etc', 'software_release', 'worked'])
tries = 50
wrapper_log = os.path.join(instance.partition_path, '.0_wrapper.log')
while tries > 0:
tries -= 1
if os.path.getsize(wrapper_log) > 0:
break
time.sleep(0.1)
self.assertLogContent(wrapper_log, 'Working')
self.assertEqual(computer.sequence,
['getFullComputerInformation'])
self.assertEqual('started', instance.state)
......
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