Skip to content

Commit

Permalink
[Ray] Move some tests out of test_ray.py (#3109)
Browse files Browse the repository at this point in the history
* move some tests to ray_cluster

* rename test_ray_cluster to test_ray_cluster_standalone
  • Loading branch information
chaokunyang committed Jun 2, 2022
1 parent f71d4ae commit 379c9fb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/platform-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ jobs:
if [ -n "$WITH_RAY_DEPLOY" ]; then
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray.py -m ray
mv .coverage build/.coverage.test_ray.file
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_cluster_standalone.py -m ray
mv .coverage build/.coverage.test_ray_cluster_standalone.file
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_client.py -m ray
mv .coverage build/.coverage.test_ray_client.file
pytest $PYTEST_CONFIG --durations=0 --timeout=200 -v -s mars/deploy/oscar/tests/test_ray_fault_injection.py -m ray
Expand Down
44 changes: 0 additions & 44 deletions mars/deploy/oscar/tests/test_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import numpy as np
import pytest

import mars
from .... import tensor as mt
from .... import dataframe as md
from ....oscar.errors import ReconstructWorkerError
Expand All @@ -32,8 +31,6 @@
_load_config,
ClusterStateActor,
new_cluster,
new_cluster_in_ray,
new_ray_session,
)
from ..session import get_default_session, new_session
from ..tests import test_local
Expand Down Expand Up @@ -190,47 +187,6 @@ def _sync_web_session_test(web_address):
return True


@require_ray
def test_new_cluster_in_ray(stop_ray):
cluster = new_cluster_in_ray(worker_num=2)
mt.random.RandomState(0).rand(100, 5).sum().execute()
cluster.session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
session = new_ray_session(address=cluster.address, session_id="abcd", default=True)
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
cluster.stop()


@require_ray
def test_new_ray_session(stop_ray):
new_ray_session_test()


def new_ray_session_test():
session = new_ray_session(session_id="abc", worker_num=2)
mt.random.RandomState(0).rand(100, 5).sum().execute()
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
session = new_ray_session(session_id="abcd", worker_num=2, default=True)
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
df = md.DataFrame(mt.random.rand(100, 4), columns=list("abcd"))
# Convert mars dataframe to ray dataset
ds = md.to_ray_dataset(df)
print(ds.schema(), ds.count())
ds.filter(lambda row: row["a"] > 0.5).show(5)
# Convert ray dataset to mars dataframe
df2 = md.read_ray_dataset(ds)
print(df2.head(5).execute())
# Test ray cluster exists after session got gc.
del session
import gc

gc.collect()
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())


@require_ray
@pytest.mark.parametrize(
"test_option",
Expand Down
2 changes: 1 addition & 1 deletion mars/deploy/oscar/tests/test_ray_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tempfile
import threading

from .test_ray import new_ray_session_test
from .test_ray_cluster_standalone import new_ray_session_test
from ....tests.core import require_ray
from ....utils import lazy_import

Expand Down
66 changes: 66 additions & 0 deletions mars/deploy/oscar/tests/test_ray_cluster_standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import mars
from .... import tensor as mt
from .... import dataframe as md
from ....tests.core import require_ray
from ....utils import lazy_import
from ..ray import (
new_cluster_in_ray,
new_ray_session,
)

ray = lazy_import("ray")


@require_ray
def test_new_cluster_in_ray(stop_ray):
cluster = new_cluster_in_ray(worker_num=2)
mt.random.RandomState(0).rand(100, 5).sum().execute()
cluster.session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
session = new_ray_session(address=cluster.address, session_id="abcd", default=True)
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
cluster.stop()


@require_ray
def test_new_ray_session(stop_ray):
new_ray_session_test()


def new_ray_session_test():
session = new_ray_session(session_id="abc", worker_num=2)
mt.random.RandomState(0).rand(100, 5).sum().execute()
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
session = new_ray_session(session_id="abcd", worker_num=2, default=True)
session.execute(mt.random.RandomState(0).rand(100, 5).sum())
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())
df = md.DataFrame(mt.random.rand(100, 4), columns=list("abcd"))
# Convert mars dataframe to ray dataset
ds = md.to_ray_dataset(df)
print(ds.schema(), ds.count())
ds.filter(lambda row: row["a"] > 0.5).show(5)
# Convert ray dataset to mars dataframe
df2 = md.read_ray_dataset(ds)
print(df2.head(5).execute())
# Test ray cluster exists after session got gc.
del session
import gc

gc.collect()
mars.execute(mt.random.RandomState(0).rand(100, 5).sum())

0 comments on commit 379c9fb

Please sign in to comment.