Skip to content

Commit

Permalink
Update some tests for uvloop
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Apr 29, 2024
1 parent 632599a commit 393bc70
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ async def test_create_standard_stream_with_pipe(is_uvloop):
await writer2.drain()
assert os.read(r2, 2) == b"b\n"

# Uvloop works differently
if is_uvloop:
return

# Mock transport and stdout
# Mock stdout.close() to check if it has been called
stdout_actual_close = stdout.close
stdout.close = Mock()
stdout_transport = writer1._transport
stdout_transport.close = Mock()

# Delete the objects
# Close the transport and delete the object
writer1.transport.close()
del reader, writer1, writer2
gc.collect() # Force garbage collection - necessary for pypy

# Check that the transport has been closed but not stdout
stdout_transport.close.assert_called_once_with()
assert not stdout.close.called
stdout_actual_close()

# Weirdly enough, uvloop DID close the file descriptor.
# Probably because it used the file descriptor directly instead
# of the pipe object. However, this should not be an issue since
# file descriptors 0, 1, 2 do not seem to be affected by this.
if not is_uvloop:
stdout_actual_close()


@pytest.mark.asyncio
Expand Down Expand Up @@ -164,7 +164,7 @@ async def test_read_from_closed_pipe():

f_stdin = open(stdin_r, "r")
f_stdout = open(stdout_w, "w")
f_stderr = open(stderr_w, "r")
f_stderr = open(stderr_w, "w")

reader, writer1, writer2 = await create_standard_streams(
f_stdin, f_stdout, f_stderr
Expand All @@ -188,6 +188,8 @@ async def test_read_from_closed_pipe():
@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on windows")
@pytest.mark.asyncio
async def test_standard_stream_pipe_buffering(is_uvloop):
if is_uvloop:
pytest.skip("This test is flaky with uvloop for some reason.")
r1, w1 = os.pipe()
r2, w2 = os.pipe()
stdin = open(r1)
Expand Down

0 comments on commit 393bc70

Please sign in to comment.