Permalink
Browse files

fix test errors

  • Loading branch information...
1 parent f15496d commit a6eb40428ef596dd59bb46297dc642178ae7ed73 @sunng87 committed Sep 30, 2011
Showing with 21 additions and 17 deletions.
  1. +15 −13 src/clojalk/core.clj
  2. +6 −4 test/clojalk/test/core.clj
View
@@ -424,13 +424,13 @@
;; not be reserved until pause timeout.
;; Also update a statistical field.
(defcommand "pause-tube" [session id timeout]
- (if-let [tube ((keyword id) @tubes)]
+ (if-let [tube (@tubes (keyword id))]
(do
- (schedule #(update-paused-tube tube) timeout)
(dosync
(ref-set (:paused tube) true)
(ref-set (:pause_deadline tube) (+ (* timeout 1000) (current-time)))
- (alter (:pauses tube) inc)))))
+ (alter (:pauses tube) inc))
+ (schedule #(update-paused-tube (:name tube)) timeout))))
;; stats command. Display some information of a job.
@@ -520,7 +520,7 @@
;; Update a delayed job and set it as ready.
;;
(defn- update-delayed-job [job-id]
- (if-let [job (job-id @jobs)]
+ (if-let [job (@jobs job-id)]
(when (= :delayed (:state job))
(dosync
(alter (:delay_set ((:tube job) @tubes)) disj job)
@@ -539,7 +539,7 @@
;; * the state of job is still `:reserved`
;;
(defn- update-expired-job [job-id]
- (if-let [job (dbg (job-id @jobs))]
+ (if-let [job (@jobs job-id)]
(when (and (>= (current-time) (:deadline_at job)) (= :reserved (:state job)))
(let [session (:reserver job)
updated-job (assoc job :state :ready
@@ -553,14 +553,16 @@
;; Enable a paused tube
;;
-(defn- update-paused-tube [tube]
- (dosync
- (ref-set (:paused tube) false)
-
- ;; handle waiting session
- (let [pending-pairs (zipmap @(:waiting_list tube) @(:ready_set tube))]
- (doseq [s (keys pending-pairs)]
- (reserve-job s (pending-pairs s))))))
+(defn- update-paused-tube [tube-name]
+ (if-let [tube (@tubes tube-name)]
+ (do
+ (dosync
+ (ref-set (:paused tube) false))
+ (dosync
+ ;; handle waiting session
+ (let [pending-pairs (zipmap @(:waiting_list tube) @(:ready_set tube))]
+ (doseq [s (keys pending-pairs)]
+ (reserve-job s (pending-pairs s))))))))
;; Reject a session that waiting for reservation
;;
@@ -218,13 +218,14 @@
(let [session-p (use (open-session :producer) "expire-tube-test")
session-w (watch (open-session :worker) "expire-tube-test")]
(put session-p 100 0 500 "nice")
- (pause-tube session-p "expire-tube-test" 0.5)
+ (pause-tube session-p "expire-tube-test" 1)
(is (true? @(:paused (:expire-tube-test @tubes))))
;; working should be waiting for tube to continue
(reserve session-w)
(is (= :waiting (:state @session-w)))
-
+
+ (sleep 1.2)
;; job could be automatically assign to pending worker
(is (= :working (:state @session-w)))
(is (false? @(:paused (:expire-tube-test @tubes))))))
@@ -276,9 +277,10 @@
(deftest test-reserve-timeout
(let [session-w (watch (open-session :worker) "test-reserve-timeout")]
;;reserve an empty tube with timeout
- (reserve-with-timeout session-w 0.5)
+ (reserve-with-timeout session-w 1)
(is (= 1 (count @(:waiting_list (:test-reserve-timeout @tubes)))))
-
+
+ (sleep 1.2)
(is (empty? @(:waiting_list (:test-reserve-timeout @tubes))))
(is (= :idle (:state @session-w)))))

0 comments on commit a6eb404

Please sign in to comment.