Skip to content

Commit

Permalink
fix timeout condition (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi authored and qinxuye committed Dec 11, 2018
1 parent ffe539e commit 4b8ad0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mars/web/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def run(self, tensors, compose=True, wait=True, timeout=-1):
if resp.status_code >= 400:
raise SystemError('Failed to stop graph execution. Code: %d, Reason: %s, Content:\n%s' %
(resp.status_code, resp.reason, resp.text))
if time.time() - exec_start_time > timeout:
if 0 < timeout < time.time() - exec_start_time:
raise TimeoutError
data_list = []
for tk in targets:
Expand Down
15 changes: 11 additions & 4 deletions mars/web/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import requests

from mars.config import options
from mars.tensor.expressions.datasource import ones
from mars import tensor as mt
from mars.web import MarsApiClient
from mars.utils import get_next_port
from mars.actors.core import new_client
Expand Down Expand Up @@ -150,9 +150,16 @@ def testApi(self):
client = MarsApiClient(service_ep)
self.assertEqual(client.count_workers(), 1)
with client.create_session() as sess:
a = ones((100, 100), chunks=30)
b = ones((100, 100), chunks=30)
a = mt.ones((100, 100), chunks=30)
b = mt.ones((100, 100), chunks=30)
c = a.dot(b)
value = sess.run(c, timeout=120)
value = sess.run(c)
assert_array_equal(value[0], np.ones((100, 100)) * 100)

va = np.random.randint(0, 10000, (100, 100))
vb = np.random.randint(0, 10000, (100, 100))
a = mt.array(va, chunks=30)
b = mt.array(vb, chunks=30)
c = a.dot(b)
value = sess.run(c, timeout=120)
assert_array_equal(value[0], va.dot(vb))

0 comments on commit 4b8ad0e

Please sign in to comment.