Skip to content

Commit

Permalink
Attempt to wait but more intelligently
Browse files Browse the repository at this point in the history
also added flaky to the test
  • Loading branch information
Austin Papp committed Feb 19, 2019
1 parent d8c744f commit b0a45e9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/integration/utils/test_master.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
'''
Test master code from utils
'''
from __future__ import absolute_import

import os
Expand All @@ -11,6 +14,7 @@

from tests.support.case import ShellTestCase
from tests.support.paths import TMP_ROOT_DIR
from tests.support.helpers import flaky

DEFAULT_CONFIG = salt.config.master_config(None)
DEFAULT_CONFIG['cachedir'] = os.path.join(TMP_ROOT_DIR, 'cache')
Expand All @@ -19,14 +23,31 @@
class MasterUtilJobsTestCase(ShellTestCase):

def setUp(self):
# Necessary so that the master pid health check
# passes as it looks for salt in cmdline
'''
Necessary so that the master pid health check
passes as it looks for salt in cmdline
'''
setproctitle.setproctitle('salt')

@flaky
def test_get_running_jobs(self):
'''
Test get running jobs
'''
ret = self.run_run_plus("test.sleep", '90', asynchronous=True)
jid = ret['jid']
time.sleep(20)
jobs = master.get_running_jobs(DEFAULT_CONFIG)

# Ran into a problem where the async jump was not seen until
# after the test had finished. This caused the test to fail
# because no job was present (not proc file). This attempts
# to wait a total of 20s before giving up.
attempt = 0
while attempt < 10:
jobs = master.get_running_jobs(DEFAULT_CONFIG)
if jobs:
break
time.sleep(2)
attempt += attempt + 1

jids = [job['jid'] for job in jobs]
assert jids.count(jid) == 1

0 comments on commit b0a45e9

Please sign in to comment.