-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There is a blocking issue caused by an await call inside a Promise Context. It was easily fixed by draining the context queue on accessing the future. Please check the test_await_in_context test in tests/test_awaitable_35.py to see an example showcasing the issue.
- Loading branch information
1 parent
6474f80
commit 26488d5
Showing
4 changed files
with
66 additions
and
1 deletion.
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
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,44 @@ | ||
from pytest import mark | ||
from promise import Promise | ||
from promise.dataloader import DataLoader | ||
|
||
|
||
def id_loader(**options): | ||
load_calls = [] | ||
|
||
resolve = options.pop('resolve', Promise.resolve) | ||
|
||
def fn(keys): | ||
load_calls.append(keys) | ||
return resolve(keys) | ||
|
||
identity_loader = DataLoader(fn, **options) | ||
return identity_loader, load_calls | ||
|
||
|
||
@mark.asyncio | ||
async def test_await_dataloader(): | ||
identity_loader, load_calls = id_loader() | ||
async def load_one_then_two(identity_loader): | ||
one = identity_loader.load('load1') | ||
two = identity_loader.load('load2') | ||
return await Promise.all([one, two]) | ||
|
||
result = await load_one_then_two(identity_loader) | ||
assert result == ['load1', 'load2'] | ||
assert load_calls == [['load1'], ['load2']] | ||
|
||
|
||
@mark.asyncio | ||
async def test_await_dataloader_safe_promise(): | ||
identity_loader, load_calls = id_loader() | ||
|
||
@Promise.safe | ||
async def load_one_then_two(identity_loader): | ||
one = identity_loader.load('load1') | ||
two = identity_loader.load('load2') | ||
return await Promise.all([one, two]) | ||
|
||
result = await load_one_then_two(identity_loader) | ||
assert result == ['load1', 'load2'] | ||
assert load_calls == [['load1'], ['load2']] |