[pypy-commit] pypy default: Add tests for the previous commit

amauryfa noreply at buildbot.pypy.org
Thu Sep 13 01:44:09 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r57312:f07eec99afa5
Date: 2012-09-13 01:43 +0200
http://bitbucket.org/pypy/pypy/changeset/f07eec99afa5/

Log:	Add tests for the previous commit

diff --git a/pypy/rlib/test/test_streamio.py b/pypy/rlib/test/test_streamio.py
--- a/pypy/rlib/test/test_streamio.py
+++ b/pypy/rlib/test/test_streamio.py
@@ -1078,6 +1078,49 @@
         assert r == ''
 
 
+class TestDiskFile:
+    def test_read_interrupted(self):
+        try:
+            from signal import alarm, signal, SIG_DFL, SIGALRM
+        except:
+            skip('no alarm on this platform')
+        try:
+            read_fd, write_fd = os.pipe()
+            file = streamio.DiskFile(read_fd)
+            def handler(*a):
+                os.write(write_fd, "hello")
+            signal(SIGALRM, handler)
+            alarm(1)
+            assert file.read(10) == "hello"
+        finally:
+            signal(SIGALRM, SIG_DFL)
+
+    def test_write_interrupted(self):
+        try:
+            from signal import alarm, signal, SIG_DFL, SIGALRM
+        except:
+            skip('no alarm on this platform')
+        try:
+            read_fd, write_fd = os.pipe()
+            file = streamio.DiskFile(write_fd)
+            def handler(*a):
+                os.read(read_fd, 2000)
+                alarm(1)
+            signal(SIGALRM, handler)
+            alarm(1)
+            # Write to the pipe until it is full
+            buf = "FILL THE PIPE" * 1000
+            while True:
+                if os.write(write_fd, buf) < len(buf):
+                    break
+            # Write more, this should block, the write() syscall is
+            # interrupted, signal handler is called, and next write()
+            # can succeed.
+            file.write("hello")
+        finally:
+            signal(SIGALRM, SIG_DFL)
+
+
 # Speed test
 
 FN = "BIG"


More information about the pypy-commit mailing list