-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported job calculation to use coroutines for tasks (#1827)
This way the event loop has a chance to schedule other operations while a transport request is made i.e. if multiple job calculations all request the same transport (a common scenario) then in the past they would all run as one loop callback effectively blocking the loop (and crucially `pika` heartbeats). Now they are schedule as separate callbacks thanks to yield, hopefully, allowing the loop to schedule other necessary tasks in between.
- Loading branch information
Showing
6 changed files
with
314 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from tornado.gen import coroutine, Return | ||
|
||
from aiida.backends.testbase import AiidaTestCase | ||
from aiida.work.transports import TransportQueue | ||
|
||
|
||
class TestTransportQueue(AiidaTestCase): | ||
""" Tests for the transport queue """ | ||
|
||
@classmethod | ||
def setUpClass(cls, *args, **kwargs): | ||
""" Set up a simple authinfo and for later use """ | ||
super(TestTransportQueue, cls).setUpClass(*args, **kwargs) | ||
# Configure the computer - no parameters for local transport | ||
# WARNING: This is not deleted as there is no API facing way to do this | ||
# it would require a backend specific call | ||
cls.authinfo = cls.backend.authinfos.create( | ||
computer=cls.computer, | ||
user=cls.backend.users.get_automatic_user()) | ||
cls.authinfo.store() | ||
|
||
def test_simple_request(self): | ||
""" Test a simple transport request """ | ||
queue = TransportQueue() | ||
loop = queue.loop() | ||
|
||
@coroutine | ||
def test(): | ||
trans = None | ||
with queue.request_transport(self.authinfo) as request: | ||
trans = yield request | ||
self.assertTrue(trans.is_open) | ||
self.assertFalse(trans.is_open) | ||
|
||
loop.run_sync(lambda: test()) | ||
|
||
def test_get_transport_nested(self): | ||
""" Test nesting calls to get the same transport """ | ||
transport_queue = TransportQueue() | ||
loop = transport_queue.loop() | ||
|
||
@coroutine | ||
def nested(queue, authinfo): | ||
with queue.request_transport(authinfo) as request1: | ||
trans1 = yield request1 | ||
self.assertTrue(trans1.is_open) | ||
with queue.request_transport(authinfo) as request2: | ||
trans2 = yield request2 | ||
self.assertIs(trans1, trans2) | ||
self.assertTrue(trans2.is_open) | ||
|
||
loop.run_sync(lambda: nested(transport_queue, self.authinfo)) | ||
|
||
def test_get_transport_interleaved(self): | ||
""" Test interleaved calls to get the same transport """ | ||
transport_queue = TransportQueue() | ||
loop = transport_queue.loop() | ||
|
||
@coroutine | ||
def interleaved(authinfo): | ||
with transport_queue.request_transport(authinfo) as trans_future: | ||
yield trans_future | ||
|
||
loop.run_sync(lambda: [interleaved(self.authinfo), interleaved(self.authinfo)]) | ||
|
||
def test_return_from_context(self): | ||
""" Test raising a Return from coroutine context """ | ||
queue = TransportQueue() | ||
loop = queue.loop() | ||
|
||
@coroutine | ||
def test(): | ||
with queue.request_transport(self.authinfo) as request: | ||
trans = yield request | ||
raise Return(trans.is_open) | ||
|
||
retval = loop.run_sync(lambda: test()) | ||
self.assertTrue(retval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.