MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_write_readline_races

Method test_write_readline_races

Lib/test/test_io.py:1084–1112  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1082
1083 @threading_helper.requires_working_threading()
1084 def test_write_readline_races(self):
1085 # gh-134908: Concurrent iteration over a file caused races
1086 thread_count = 2
1087 write_count = 100
1088 read_count = 100
1089
1090 def writer(file, barrier):
1091 barrier.wait()
1092 for _ in range(write_count):
1093 file.write("x")
1094
1095 def reader(file, barrier):
1096 barrier.wait()
1097 for _ in range(read_count):
1098 for line in file:
1099 self.assertEqual(line, "")
1100
1101 with self.open(os_helper.TESTFN, "w+") as f:
1102 barrier = threading.Barrier(thread_count + 1)
1103 reader = threading.Thread(target=reader, args=(f, barrier))
1104 writers = [threading.Thread(target=writer, args=(f, barrier))
1105 for _ in range(thread_count)]
1106 with threading_helper.catch_threading_exception() as cm:
1107 with threading_helper.start_threads(writers + [reader]):
1108 pass
1109 self.assertIsNone(cm.exc_type)
1110
1111 self.assertEqual(os.stat(os_helper.TESTFN).st_size,
1112 write_count * thread_count)
1113
1114
1115class CIOTest(IOTest):

Callers

nothing calls this directly

Calls 5

BarrierMethod · 0.80
assertIsNoneMethod · 0.80
openMethod · 0.45
assertEqualMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected