Skip to content

Commit

Permalink
back to 100% coverage, but keep polling after max_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
escapewindow committed May 3, 2016
1 parent 51ce807 commit 8eca14e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions scriptworker/worker.py
Expand Up @@ -78,5 +78,9 @@ def main():
'accessToken': context.config['taskcluster_access_token'],
}
}, session=context.session)
loop.create_task(async_main(context))
loop.run_forever()
while True:
try:
loop.create_task(async_main(context))
loop.run_forever()
except RuntimeError:
pass
20 changes: 16 additions & 4 deletions tests/test_worker.py
Expand Up @@ -2,6 +2,7 @@
# coding=utf-8
"""Test scriptworker.worker
"""
import asyncio
from copy import deepcopy
import datetime
import mock
Expand Down Expand Up @@ -57,13 +58,24 @@ def test_main_bad_json(self, event_loop):
def test_main(self, mocker, event_loop):
path = os.path.join(os.path.dirname(__file__), "data", "good.json")
config = create_config(path)
loop = mock.MagicMock()
exceptions = [RuntimeError, ScriptWorkerException]

def run_forever():
exc = exceptions.pop(0)
raise exc("foo")

def foo(arg):
assert arg.config == config
mocker.patch('sys.argv', new=[__file__, path])
mocker.patch('asyncio.get_event_loop')
mocker.patch('scriptworker.worker.async_main', new=foo)
worker.main()

loop.run_forever = run_forever

mocker.patch.object(sys, 'argv', new=[__file__, path])
mocker.patch.object(worker, 'async_main', new=foo)
with mock.patch.object(asyncio, 'get_event_loop') as p:
p.return_value = loop
with pytest.raises(ScriptWorkerException):
worker.main()

@pytest.mark.asyncio
async def test_async_main(self, context):
Expand Down

0 comments on commit 8eca14e

Please sign in to comment.