Skip to content

Commit 05e9afd

Browse files
committed
Add tests for concurrent detach
1 parent 5dbe999 commit 05e9afd

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

Lib/test/test_io/test_bufferedio.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def test_read1_error_does_not_cause_reentrant_failure(self):
642642
# Used to crash before gh-143689:
643643
self.assertEqual(bufio.read1(1), b"h")
644644

645-
def test_gh_143375(self):
645+
def test_concurrent_close(self):
646646
bufio = self.tp(self.MockRawIO())
647647

648648
class EvilIndex:
@@ -653,6 +653,17 @@ def __index__(self):
653653
with self.assertRaisesRegex(ValueError, "seek of closed file"):
654654
bufio.seek(EvilIndex())
655655

656+
def test_concurrent_detach(self):
657+
bufio = self.tp(self.MockRawIO())
658+
659+
class EvilIndex:
660+
def __index__(self):
661+
bufio.detach()
662+
return 0
663+
664+
with self.assertRaisesRegex(ValueError, "raw stream has been detached"):
665+
bufio.seek(EvilIndex())
666+
656667
class PyBufferedReaderTest(BufferedReaderTest, PyTestCase):
657668
tp = pyio.BufferedReader
658669

@@ -1012,7 +1023,7 @@ def closed(self):
10121023
self.assertRaisesRegex(ValueError, "test", bufio.flush)
10131024
self.assertRaisesRegex(ValueError, "test", bufio.close)
10141025

1015-
def test_gh_143375(self):
1026+
def test_concurrent_close(self):
10161027
bufio = self.tp(self.MockRawIO())
10171028

10181029
class EvilIndex:
@@ -1023,6 +1034,17 @@ def __index__(self):
10231034
with self.assertRaisesRegex(ValueError, "seek of closed file"):
10241035
bufio.seek(EvilIndex())
10251036

1037+
def test_concurrent_detach(self):
1038+
bufio = self.tp(self.MockRawIO())
1039+
1040+
class EvilIndex:
1041+
def __index__(self):
1042+
bufio.detach()
1043+
return 0
1044+
1045+
with self.assertRaisesRegex(ValueError, "raw stream has been detached"):
1046+
bufio.seek(EvilIndex())
1047+
10261048

10271049
class PyBufferedWriterTest(BufferedWriterTest, PyTestCase):
10281050
tp = pyio.BufferedWriter
@@ -1514,7 +1536,7 @@ def test_args_error(self):
15141536
with self.assertRaisesRegex(TypeError, "BufferedRandom"):
15151537
self.tp(self.BytesIO(), 1024, 1024, 1024)
15161538

1517-
def test_gh_143375(self):
1539+
def test_concurrent_close(self):
15181540
bufio = self.tp(self.MockRawIO())
15191541

15201542
class EvilIndex:
@@ -1525,6 +1547,17 @@ def __index__(self):
15251547
with self.assertRaisesRegex(ValueError, "seek of closed file"):
15261548
bufio.seek(EvilIndex())
15271549

1550+
def test_concurrent_detach(self):
1551+
bufio = self.tp(self.MockRawIO())
1552+
1553+
class EvilIndex:
1554+
def __index__(self):
1555+
bufio.detach()
1556+
return 0
1557+
1558+
with self.assertRaisesRegex(ValueError, "raw stream has been detached"):
1559+
bufio.seek(EvilIndex())
1560+
15281561

15291562
class PyBufferedRandomTest(BufferedRandomTest, PyTestCase):
15301563
tp = pyio.BufferedRandom

0 commit comments

Comments
 (0)