-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better checking that ray.init() has been called. (#10261)
- Loading branch information
1 parent
d4537ac
commit 79eefbf
Showing
7 changed files
with
92 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,54 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
import ray | ||
|
||
|
||
def test_errors_before_initializing_ray(): | ||
@ray.remote | ||
def f(): | ||
pass | ||
|
||
@ray.remote | ||
class Foo: | ||
pass | ||
|
||
api_methods = [ | ||
f.remote, | ||
Foo.remote, | ||
ray.actors, | ||
lambda: ray.cancel(None), # Not valid API usage. | ||
lambda: ray.get([]), | ||
lambda: ray.get_actor("name"), | ||
ray.get_gpu_ids, | ||
ray.get_resource_ids, | ||
ray.get_webui_url, | ||
ray.jobs, | ||
lambda: ray.kill(None), # Not valid API usage. | ||
ray.nodes, | ||
ray.objects, | ||
lambda: ray.put(1), | ||
lambda: ray.wait([]) | ||
] | ||
|
||
def test_exceptions_raised(): | ||
for api_method in api_methods: | ||
print(api_method) | ||
with pytest.raises( | ||
ray.exceptions.RayConnectionError, | ||
match="Ray has not been started yet."): | ||
api_method() | ||
|
||
test_exceptions_raised() | ||
|
||
# Make sure that the exceptions are still raised after Ray has been | ||
# started and shutdown. | ||
ray.init(num_cpus=0) | ||
ray.shutdown() | ||
|
||
test_exceptions_raised() | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main(["-v", __file__])) |
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