Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r72310:1a8c4f5e30da
Date: 2014-07-02 08:49 +0200
http://bitbucket.org/pypy/pypy/changeset/1a8c4f5e30da/

Log:    test: doing a large number of ping-pongs between two threads, using
        locks, should complete in a reasonable time on a translated pypy
        with -A.

diff --git a/pypy/module/thread/test/support.py 
b/pypy/module/thread/test/support.py
--- a/pypy/module/thread/test/support.py
+++ b/pypy/module/thread/test/support.py
@@ -44,6 +44,7 @@
     spaceconfig = dict(usemodules=('thread', 'rctime', 'signal'))
 
     def setup_class(cls):
+        cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
         if cls.runappdirect:
             def plain_waitfor(self, condition, delay=1):
                 adaptivedelay = 0.04
diff --git a/pypy/module/thread/test/test_lock.py 
b/pypy/module/thread/test/test_lock.py
--- a/pypy/module/thread/test/test_lock.py
+++ b/pypy/module/thread/test/test_lock.py
@@ -57,8 +57,34 @@
         assert lock.acquire() is True
         assert lock.acquire(False) is False
         raises(TypeError, lock.acquire, True, timeout=.1)
-        lock._py3k_acquire(True, timeout=.01)
-        lock._py3k_acquire(True, .01)
+        if hasattr(lock, '_py3k_acquire'):
+            lock._py3k_acquire(True, timeout=.01)
+            lock._py3k_acquire(True, .01)
+        else:
+            assert self.runappdirect, "missing lock._py3k_acquire()"
+
+    def test_ping_pong(self):
+        # The purpose of this test is that doing a large number of ping-pongs
+        # between two threads, using locks, should complete in a reasonable
+        # time on a translated pypy with -A.  If the GIL logic causes too
+        # much sleeping, then it will fail.
+        import thread, time
+        COUNT = 100000 if self.runappdirect else 50
+        lock1 = thread.allocate_lock()
+        lock2 = thread.allocate_lock()
+        def fn():
+            for i in range(COUNT):
+                lock1.acquire()
+                lock2.release()
+        lock2.acquire()
+        print "STARTING"
+        start = time.time()
+        thread.start_new_thread(fn, ())
+        for i in range(COUNT):
+            lock2.acquire()
+            lock1.release()
+        stop = time.time()
+        assert stop - start < 30.0    # ~0.6 sec on pypy-c-jit
 
 
 def test_compile_lock():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to