Skip to content

Commit 5110fa2

Browse files
committed
Use fsync in the child to force writing to disk
1 parent 1ad0a08 commit 5110fa2

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

Lib/test/test_posix.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,9 +1527,10 @@ def test_open_file(self):
15271527
outfile = support.TESTFN
15281528
self.addCleanup(support.unlink, outfile)
15291529
script = """if 1:
1530-
import sys
1530+
import sys, os
15311531
sys.stdout.write("hello")
15321532
sys.stdout.flush()
1533+
os.fsync(sys.stdout.fileno())
15331534
"""
15341535
file_actions = [
15351536
(os.POSIX_SPAWN_OPEN, 1, outfile,
@@ -1540,23 +1541,8 @@ def test_open_file(self):
15401541
[sys.executable, '-c', script],
15411542
os.environ, file_actions)
15421543
self.assertEqual(os.waitpid(pid, 0), (pid, 0))
1543-
1544-
deadline = time.monotonic() + 0.3
1545-
while not os.path.exists(outfile):
1546-
if time.monotonic() > deadline:
1547-
raise TimeoutError
1548-
time.sleep(0.1)
1549-
1550-
deadline = time.monotonic() + 0.3
15511544
with open(outfile) as f:
1552-
while True:
1553-
if time.monotonic() > deadline:
1554-
raise TimeoutError
1555-
f.seek(0)
1556-
data = f.read()
1557-
if data:
1558-
break
1559-
self.assertEqual(data, 'hello')
1545+
self.assertEqual(f.read(), 'hello')
15601546

15611547
def test_close_file(self):
15621548
closefile = support.TESTFN

0 commit comments

Comments
 (0)