Skip to content

Commit

Permalink
[Serve] Unskipped tests in test_pipeline.py (ray-project#21484)
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 authored Jan 12, 2022
1 parent 188324c commit 13f20e5
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions python/ray/serve/pipeline/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,42 @@ def __call__(self, name: str):
assert greeter.call("Theodore") == "Top of the morning Theodore!"


@pytest.mark.skipif(sys.platform == "win32", reason="File handling.")
@pytest.mark.parametrize("execution_mode", ALL_EXECUTION_MODES)
@enable_local_execution_mode_only
def test_class_constructor_not_called_until_deployed(execution_mode,
shared_ray_instance):
"""Constructor should only be called after .deploy()."""

with tempfile.NamedTemporaryFile("w") as tmp:
tmp = tempfile.NamedTemporaryFile("w+", suffix=".tmp", delete=False)
tmp.close()

@pipeline.step(execution_mode=execution_mode)
class FileWriter:
def __init__(self, tmpfile: str, msg: str):
with open(tmpfile, "w") as f:
f.write(msg)
f.flush()
@pipeline.step(execution_mode=execution_mode)
class FileWriter:
def __init__(self, tmpfile_name, msg: str):
with open(tmpfile_name, "w") as tmpfile:
tmpfile.write(msg)
tmpfile.flush()

def __call__(self, arg: str):
return arg

def __call__(self, arg: str):
return arg
msg = "hello"

msg = "hello"
def constructor_called():
with open(tmp.name, "r") as f:
ret = f.readline() == msg
return ret

def constructor_called():
with open(tmp.name, "r") as f:
return f.read() == msg
file_writer = FileWriter(tmp.name, msg)
assert not constructor_called()

file_writer = FileWriter(tmp.name, msg)
assert not constructor_called()
writer_pipeline = file_writer(pipeline.INPUT)
assert not constructor_called()

writer_pipeline = file_writer(pipeline.INPUT)
assert not constructor_called()
assert writer_pipeline.deploy().call("hi") == "hi"
assert constructor_called()

assert writer_pipeline.deploy().call("hi") == "hi"
assert constructor_called()
os.unlink(tmp.name)


@pytest.mark.parametrize("execution_mode", ALL_EXECUTION_MODES)
Expand Down

0 comments on commit 13f20e5

Please sign in to comment.