[pypy-svn] r60358 - in pypy/trunk/pypy/rlib: . test

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Dec 8 12:57:50 CET 2008


Author: xoraxax
Date: Mon Dec  8 12:57:50 2008
New Revision: 60358

Modified:
   pypy/trunk/pypy/rlib/rpoll.py
   pypy/trunk/pypy/rlib/test/test_rpoll.py
Log:
Fix rpolls select to adhere to the correct timeout.

Modified: pypy/trunk/pypy/rlib/rpoll.py
==============================================================================
--- pypy/trunk/pypy/rlib/rpoll.py	(original)
+++ pypy/trunk/pypy/rlib/rpoll.py	Mon Dec  8 12:57:50 2008
@@ -105,7 +105,7 @@
         ll_timeval = lltype.malloc(_c.timeval, flavor='raw')
         frac = math.fmod(timeout, 1.0)
         ll_timeval.c_tv_sec = int(timeout)
-        ll_timeval.c_tv_usec = int(timeout*1000000.0)
+        ll_timeval.c_tv_usec = int((timeout - int(timeout)) * 1000000.0)
     else:
         ll_timeval = lltype.nullptr(_c.timeval)
     try:

Modified: pypy/trunk/pypy/rlib/test/test_rpoll.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rpoll.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_rpoll.py	Mon Dec  8 12:57:50 2008
@@ -50,6 +50,7 @@
     serv.close()
 
 def test_select():
+    from time import time
     def f():
         readend, writeend = os.pipe()
         try:
@@ -59,10 +60,17 @@
             iwtd, owtd, ewtd = select([readend], [], [])
             assert iwtd == [readend]
             assert owtd == ewtd == []
+
         finally:
             os.close(readend)
             os.close(writeend)
 
+        # once there was a bug where the sleeping time was doubled
+        a = time()
+        iwtd, owtd, ewtd = select([], [], [], 1.0)
+        diff = time() - a
+        assert 0.9 < diff < 1.1
+
     f()
     interpret(f, [])
 



More information about the Pypy-commit mailing list