-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not call the async wrapper calls with the separate thread
* Do not run method with the distinct thread * Move test_asynchronous.py to pytests
- Loading branch information
Showing
3 changed files
with
94 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import tornado.gen | ||
import tornado.ioloop | ||
|
||
import salt.utils.asynchronous as asynchronous | ||
|
||
|
||
class HelperA: | ||
|
||
async_methods = [ | ||
"sleep", | ||
] | ||
|
||
def __init__(self, io_loop=None): | ||
pass | ||
|
||
@tornado.gen.coroutine | ||
def sleep(self): | ||
yield tornado.gen.sleep(0.1) | ||
raise tornado.gen.Return(True) | ||
|
||
|
||
class HelperB: | ||
|
||
async_methods = [ | ||
"sleep", | ||
] | ||
|
||
def __init__(self, a=None, io_loop=None): | ||
if a is None: | ||
a = asynchronous.SyncWrapper(HelperA) | ||
self.a = a | ||
|
||
@tornado.gen.coroutine | ||
def sleep(self): | ||
yield tornado.gen.sleep(0.1) | ||
self.a.sleep() | ||
raise tornado.gen.Return(False) | ||
|
||
|
||
def test_helpers(): | ||
""" | ||
Test that the helper classes do what we expect within a regular asynchronous env | ||
""" | ||
io_loop = tornado.ioloop.IOLoop(make_current=False) | ||
ret = io_loop.run_sync(lambda: HelperA().sleep()) | ||
assert ret is True | ||
|
||
ret = io_loop.run_sync(lambda: HelperB().sleep()) | ||
assert ret is False | ||
|
||
|
||
def test_basic_wrap(): | ||
""" | ||
Test that we can wrap an asynchronous caller. | ||
""" | ||
sync = asynchronous.SyncWrapper(HelperA) | ||
ret = sync.sleep() | ||
assert ret is True | ||
|
||
|
||
def test_basic_wrap_series(): | ||
""" | ||
Test that we can wrap an asynchronous caller and call the method in series. | ||
""" | ||
sync = asynchronous.SyncWrapper(HelperA) | ||
ret = sync.sleep() | ||
assert ret is True | ||
ret = sync.sleep() | ||
assert ret is True | ||
|
||
|
||
def test_double(): | ||
""" | ||
Test when the asynchronous wrapper object itself creates a wrap of another thing | ||
This works fine since the second wrap is based on the first's IOLoop so we | ||
don't have to worry about complex start/stop mechanics | ||
""" | ||
sync = asynchronous.SyncWrapper(HelperB) | ||
ret = sync.sleep() | ||
assert ret is False | ||
|
||
|
||
def test_double_sameloop(): | ||
""" | ||
Test asynchronous wrappers initiated from the same IOLoop, to ensure that | ||
we don't wire up both to the same IOLoop (since it causes MANY problems). | ||
""" | ||
a = asynchronous.SyncWrapper(HelperA) | ||
sync = asynchronous.SyncWrapper(HelperB, (a,)) | ||
ret = sync.sleep() | ||
assert ret is False |
This file was deleted.
Oops, something went wrong.