Skip to content

Commit

Permalink
Improved test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Aug 6, 2016
1 parent 9270114 commit 480040a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_awaitable.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import asyncio
import pytest
import time
from promise import Promise


@pytest.mark.asyncio
@asyncio.coroutine
def test_await():
yield from Promise.resolve(True)


@pytest.mark.asyncio
@asyncio.coroutine
def test_await_time():
def resolve_or_reject(resolve, reject):
time.sleep(.1)
resolve(True)
p = Promise(resolve_or_reject)
assert p.get() is True
21 changes: 21 additions & 0 deletions tests/test_complex_threads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time
import concurrent.futures
from promise import Promise
executor = concurrent.futures.ThreadPoolExecutor(max_workers=40000);


def combine(r,n):
return r * n


def promise_factorial(n):
if n < 2:
return 1
time.sleep(.02)
a = executor.submit(promise_factorial, n - 1)
return Promise.promisify(a).then(lambda r: combine(r, n))


def test_factorial():
p = promise_factorial(10)
assert p.get() == 3628800

0 comments on commit 480040a

Please sign in to comment.