-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from jacobtomlinson/async-support
Async cluster creation
- Loading branch information
Showing
9 changed files
with
178 additions
and
60 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
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,5 @@ | ||
from dask_cloudprovider.gcp.utils import build_request | ||
|
||
|
||
def test_build_request(): | ||
assert build_request()(None, lambda x: x, "https://example.com") |
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,14 @@ | ||
import httplib2 | ||
import googleapiclient.http | ||
import google_auth_httplib2 | ||
|
||
|
||
def build_request(credentials=None): | ||
def inner(http, *args, **kwargs): | ||
new_http = httplib2.Http() | ||
if credentials is not None: | ||
new_http = google_auth_httplib2.AuthorizedHttp(credentials, http=new_http) | ||
|
||
return googleapiclient.http.HttpRequest(new_http, *args, **kwargs) | ||
|
||
return inner |
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 |
---|---|---|
@@ -1,9 +1,55 @@ | ||
import pytest | ||
|
||
from dask_cloudprovider.generic.vmcluster import VMCluster | ||
import asyncio | ||
import time | ||
|
||
from dask_cloudprovider.generic.vmcluster import VMCluster, VMInterface | ||
|
||
|
||
class DummyWorker(VMInterface): | ||
"""A dummy worker for testing.""" | ||
|
||
|
||
class DummyScheduler(VMInterface): | ||
"""A dummy scheduler for testing.""" | ||
|
||
|
||
class DummyCluster(VMCluster): | ||
"""A dummy cluster for testing.""" | ||
|
||
scheduler_class = DummyScheduler | ||
worker_class = DummyWorker | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_init(): | ||
with pytest.raises(RuntimeError): | ||
_ = VMCluster(asynchronous=True) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_call_async(): | ||
cluster = DummyCluster(asynchronous=True) | ||
|
||
def blocking(string): | ||
time.sleep(0.1) | ||
return string | ||
|
||
start = time.time() | ||
|
||
a, b, c, d = await asyncio.gather( | ||
cluster.call_async(blocking, "hello"), | ||
cluster.call_async(blocking, "world"), | ||
cluster.call_async(blocking, "foo"), | ||
cluster.call_async(blocking, "bar"), | ||
) | ||
|
||
assert a == "hello" | ||
assert b == "world" | ||
assert c == "foo" | ||
assert d == "bar" | ||
|
||
# Each call to ``blocking`` takes 0.1 seconds, but they should've been run concurrently. | ||
assert time.time() - start < 0.2 | ||
|
||
await cluster.close() |
Oops, something went wrong.