]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix last change
authorEli Zaretskii <eliz@gnu.org>
Fri, 13 Jan 2017 16:17:12 +0000 (18:17 +0200)
committerEli Zaretskii <eliz@gnu.org>
Fri, 13 Jan 2017 16:17:12 +0000 (18:17 +0200)
* test/src/thread-tests.el (threads-condvar-wait): Revert
previous change.  Make sure no other threads from previous
tests are running, to avoid interfering with our thread counts.

test/src/thread-tests.el

index 22ea90727ce830416b3bda33e8142ded898759e0..df8222a21aa1866d756ce1117b13a0f0b45cebfd 100644 (file)
 (ert-deftest threads-condvar-wait ()
   "test waiting on conditional variable"
   (let ((cv-mutex (make-mutex))
-        (nthreads (length (all-threads)))
         new-thread)
+    ;; We could have spurious threads from the previous tests still
+    ;; running; wait for them to die.
+    (while (> (length (all-threads)) 1)
+      (thread-yield))
     (setq threads-condvar (make-condition-variable cv-mutex))
     (setq new-thread (make-thread #'threads-test-condvar-wait))
 
     ;; Make sure new-thread is alive.
     (should (thread-alive-p new-thread))
-    (should (= (length (all-threads)) (1+ nthreads)))
+    (should (= (length (all-threads)) 2))
     ;; Wait for new-thread to become blocked on the condvar.
     (while (not (eq (thread--blocker new-thread) threads-condvar))
       (thread-yield))
     ;; Notify the waiting thread.
     (with-mutex cv-mutex
       (condition-notify threads-condvar t))
-    ;; Allow new-thread to process the notification.  Sleeping for too
-    ;; short time here will fail the length test below.
-    (sleep-for 1)
+    ;; Allow new-thread to process the notification.
+    (sleep-for 0.1)
     ;; Make sure the thread is still there.  This used to fail due to
     ;; a bug in thread.c:condition_wait_callback.
     (should (thread-alive-p new-thread))
-    (should (= (length (all-threads)) (1+ nthreads)))
-    (should (memq new-thread (all-threads)))
-    ;; Make sure the other thread waits at the condition variable again.
+    (should (= (length (all-threads)) 2))
     (should (eq (thread--blocker new-thread) threads-condvar))
 
     ;; Signal the thread.
     (thread-signal new-thread 'error '("Die, die, die!"))
     (sleep-for 0.1)
     ;; Make sure the thread died.
-    (should (= (length (all-threads)) nthreads))))
+    (should (= (length (all-threads)) 1))))
 
 ;;; threads.el ends here