Skip to content

Commit 379c9fb

Browse files
authored
[Ray] Move some tests out of test_ray.py (#3109)
* move some tests to ray_cluster * rename test_ray_cluster to test_ray_cluster_standalone
1 parent f71d4ae commit 379c9fb

File tree

4 files changed

+69
-45
lines changed

4 files changed

+69
-45
lines changed

.github/workflows/platform-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ jobs:
154154
if [ -n "$WITH_RAY_DEPLOY" ]; then
155155
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray.py -m ray
156156
mv .coverage build/.coverage.test_ray.file
157+
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_cluster_standalone.py -m ray
158+
mv .coverage build/.coverage.test_ray_cluster_standalone.file
157159
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_client.py -m ray
158160
mv .coverage build/.coverage.test_ray_client.file
159161
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_fault_injection.py -m ray

mars/deploy/oscar/tests/test_ray.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import numpy as np
2222
import pytest
2323

24-
import mars
2524
from .... import tensor as mt
2625
from .... import dataframe as md
2726
from ....oscar.errors import ReconstructWorkerError
@@ -32,8 +31,6 @@
3231
_load_config,
3332
ClusterStateActor,
3433
new_cluster,
35-
new_cluster_in_ray,
36-
new_ray_session,
3734
)
3835
from ..session import get_default_session, new_session
3936
from ..tests import test_local
@@ -190,47 +187,6 @@ def _sync_web_session_test(web_address):
190187
return True
191188

192189

193-
@require_ray
194-
def test_new_cluster_in_ray(stop_ray):
195-
cluster = new_cluster_in_ray(worker_num=2)
196-
mt.random.RandomState(0).rand(100, 5).sum().execute()
197-
cluster.session.execute(mt.random.RandomState(0).rand(100, 5).sum())
198-
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
199-
session = new_ray_session(address=cluster.address, session_id="abcd", default=True)
200-
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
201-
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
202-
cluster.stop()
203-
204-
205-
@require_ray
206-
def test_new_ray_session(stop_ray):
207-
new_ray_session_test()
208-
209-
210-
def new_ray_session_test():
211-
session = new_ray_session(session_id="abc", worker_num=2)
212-
mt.random.RandomState(0).rand(100, 5).sum().execute()
213-
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
214-
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
215-
session = new_ray_session(session_id="abcd", worker_num=2, default=True)
216-
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
217-
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
218-
df = md.DataFrame(mt.random.rand(100, 4), columns=list("abcd"))
219-
# Convert mars dataframe to ray dataset
220-
ds = md.to_ray_dataset(df)
221-
print(ds.schema(), ds.count())
222-
ds.filter(lambda row: row["a"] > 0.5).show(5)
223-
# Convert ray dataset to mars dataframe
224-
df2 = md.read_ray_dataset(ds)
225-
print(df2.head(5).execute())
226-
# Test ray cluster exists after session got gc.
227-
del session
228-
import gc
229-
230-
gc.collect()
231-
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
232-
233-
234190
@require_ray
235191
@pytest.mark.parametrize(
236192
"test_option",

mars/deploy/oscar/tests/test_ray_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import tempfile
1818
import threading
1919

20-
from .test_ray import new_ray_session_test
20+
from .test_ray_cluster_standalone import new_ray_session_test
2121
from ....tests.core import require_ray
2222
from ....utils import lazy_import
2323

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 1999-2021 Alibaba Group Holding Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import mars
16+
from .... import tensor as mt
17+
from .... import dataframe as md
18+
from ....tests.core import require_ray
19+
from ....utils import lazy_import
20+
from ..ray import (
21+
new_cluster_in_ray,
22+
new_ray_session,
23+
)
24+
25+
ray = lazy_import("ray")
26+
27+
28+
@require_ray
29+
def test_new_cluster_in_ray(stop_ray):
30+
cluster = new_cluster_in_ray(worker_num=2)
31+
mt.random.RandomState(0).rand(100, 5).sum().execute()
32+
cluster.session.execute(mt.random.RandomState(0).rand(100, 5).sum())
33+
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
34+
session = new_ray_session(address=cluster.address, session_id="abcd", default=True)
35+
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
36+
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
37+
cluster.stop()
38+
39+
40+
@require_ray
41+
def test_new_ray_session(stop_ray):
42+
new_ray_session_test()
43+
44+
45+
def new_ray_session_test():
46+
session = new_ray_session(session_id="abc", worker_num=2)
47+
mt.random.RandomState(0).rand(100, 5).sum().execute()
48+
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
49+
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
50+
session = new_ray_session(session_id="abcd", worker_num=2, default=True)
51+
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
52+
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
53+
df = md.DataFrame(mt.random.rand(100, 4), columns=list("abcd"))
54+
# Convert mars dataframe to ray dataset
55+
ds = md.to_ray_dataset(df)
56+
print(ds.schema(), ds.count())
57+
ds.filter(lambda row: row["a"] > 0.5).show(5)
58+
# Convert ray dataset to mars dataframe
59+
df2 = md.read_ray_dataset(ds)
60+
print(df2.head(5).execute())
61+
# Test ray cluster exists after session got gc.
62+
del session
63+
import gc
64+
65+
gc.collect()
66+
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())

0 commit comments

Comments
 (0)