Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(SERVER-150) Put a 'retry' poison pill in the flushed pool
When we replace the old pool with the new pool during a 'flush' request, we need to have a way to handle the possible race condition where some code has a reference to the old pool and tries to borrow an instance from it after it has already been flushed. This commit is the first step towards that; it puts a RetryPoisonPill into the old queue.
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/unit/puppetlabs/services/jruby/jruby_puppet_agents_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(ns puppetlabs.services.jruby.jruby-puppet-agents-test | ||
(:require [clojure.test :refer :all] | ||
[schema.test :as schema-test] | ||
[puppetlabs.trapperkeeper.testutils.bootstrap :as tk-testutils] | ||
[puppetlabs.services.jruby.jruby-puppet-service :as jruby] | ||
[puppetlabs.services.puppet-profiler.puppet-profiler-service :as profiler] | ||
[puppetlabs.services.jruby.jruby-testutils :as jruby-testutils] | ||
[puppetlabs.services.jruby.jruby-puppet-core :as jruby-core] | ||
[puppetlabs.trapperkeeper.app :as tk-app] | ||
[puppetlabs.trapperkeeper.services :as tk-services] | ||
[puppetlabs.services.protocols.jruby-puppet :as jruby-protocol]) | ||
(:import (puppetlabs.services.jruby.jruby_puppet_core RetryPoisonPill))) | ||
|
||
(use-fixtures :once schema-test/validate-schemas) | ||
|
||
(deftest retry-poison-pill-test | ||
(testing "Flush puts a retry poison pill into the old pool" | ||
(tk-testutils/with-app-with-config | ||
app | ||
[jruby/jruby-puppet-pooled-service | ||
profiler/puppet-profiler-service] | ||
(-> (jruby-testutils/jruby-puppet-tk-config | ||
(jruby-testutils/jruby-puppet-config 1))) | ||
(let [jruby-service (tk-app/get-service app :JRubyPuppetService) | ||
context (tk-services/service-context jruby-service) | ||
pool-context (:pool-context context) | ||
old-pool (jruby-core/get-pool pool-context) | ||
pool-state-swapped (promise) | ||
pool-state-watch-fn (fn [key pool-state old-val new-val] | ||
(when (not= (:pool old-val) (:pool new-val)) | ||
(remove-watch pool-state key) | ||
(deliver pool-state-swapped true)))] | ||
; borrow an instance so we know that the pool is ready | ||
(jruby/with-jruby-puppet jruby-puppet jruby-service) | ||
(add-watch (:pool-state pool-context) :pool-state-watch pool-state-watch-fn) | ||
(jruby-protocol/flush-jruby-pool! jruby-service) | ||
; wait until we know the new pool has been swapped in | ||
@pool-state-swapped | ||
; wait until the flush is complete | ||
(await (:pool-agent context)) | ||
(let [old-pool-instance (jruby-core/borrow-from-pool old-pool)] | ||
(is (jruby-core/retry-poison-pill? old-pool-instance))))))) |