Skip to content

Commit e386a54

Browse files
committed
review
- simplify test (remove threads)
1 parent a1f3470 commit e386a54

1 file changed

Lines changed: 10 additions & 28 deletions

File tree

‎test/test_util.py‎

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import contextlib
77
import errno
8-
from datetime import datetime
9-
from io import BytesIO, StringIO
108
import os
119
import pathlib
1210
import pickle
1311
import stat
1412
import sys
1513
import threading
1614
import time
15+
from datetime import datetime
16+
from io import BytesIO, StringIO
1717
from unittest import SkipTest, mock
1818

1919
import ddt
@@ -44,8 +44,8 @@
4444
stream_copy,
4545
)
4646
from test.cleanup import cleanup_directory
47-
from test.lib.fixtures import writable_fixture
4847
from test.lib import TestBase, requires_symlinks, with_rw_repo
48+
from test.lib.fixtures import writable_fixture
4949

5050

5151
@pytest.mark.parametrize(
@@ -69,38 +69,20 @@ def read(self, size):
6969
@pytest.mark.skipif(sys.platform == "win32", reason="requires POSIX unbuffered pipe reads")
7070
def test_stream_copy_keeps_reading_an_unbuffered_pipe():
7171
read_fd, write_fd = os.pipe()
72-
first_copied = threading.Event()
73-
errors = []
7472

7573
class Destination(BytesIO):
7674
def write(self, data):
7775
result = super().write(data)
78-
if data:
79-
first_copied.set()
76+
if data and not writer.closed:
77+
# Make the second chunk available only after the first short read is copied.
78+
writer.write(b"second")
79+
writer.close()
8080
return result
8181

82-
def produce():
83-
try:
84-
os.write(write_fd, b"first-")
85-
if not first_copied.wait(5):
86-
raise RuntimeError("first pipe chunk was not copied")
87-
os.write(write_fd, b"second")
88-
except Exception as error:
89-
errors.append(error)
90-
finally:
91-
os.close(write_fd)
92-
9382
destination = Destination()
94-
with os.fdopen(read_fd, "rb", buffering=0) as source:
95-
thread = threading.Thread(target=produce)
96-
thread.start()
97-
try:
98-
copied = stream_copy(source, destination, chunk_size=1024)
99-
finally:
100-
first_copied.set()
101-
thread.join(5)
102-
assert not thread.is_alive()
103-
assert not errors
83+
with os.fdopen(read_fd, "rb", buffering=0) as source, os.fdopen(write_fd, "wb", buffering=0) as writer:
84+
writer.write(b"first-")
85+
copied = stream_copy(source, destination, chunk_size=1024)
10486
assert copied == len(b"first-second")
10587
assert destination.getvalue() == b"first-second"
10688

0 commit comments

Comments
 (0)