Skip to content

Commit

Permalink
Merge pull request ManageIQ#16477 from carbonin/alter_connection_pool…
Browse files Browse the repository at this point in the history
…_for_embedded_ansible

Add a connection to the pool if there is only one for embedded ansible
  • Loading branch information
jrafanie authored Nov 15, 2017
2 parents bda23f4 + a3f50f1 commit 57b5da5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/models/embedded_ansible_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def start_runner
end

def start_monitor_thread
fix_connection_pool

t = Thread.new do
begin
self.class::Runner.start_worker(worker_options)
Expand Down Expand Up @@ -58,4 +60,13 @@ def status_update

# Base class methods we override since we don't have a separate process. We might want to make these opt-in features in the base class that this subclass can choose to opt-out.
def release_db_connection; end

private

def fix_connection_pool
# If we only have one connection in the pool, it will be being used by the server
# Add another so we can start the worker thread
current = ActiveRecord::Base.connection_pool.instance_variable_get(:@size)
ActiveRecord::Base.connection_pool.instance_variable_set(:@size, 2) if current == 1
end
end
15 changes: 14 additions & 1 deletion spec/models/embedded_ansible_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,26 @@
end

describe "#start_monitor_thread" do
it "sets worker class and id in thread object" do
let(:pool) { double("ConnectionPool") }

before do
allow(Thread).to receive(:new).and_return({})
allow(described_class::Runner).to receive(:start_worker)
end

it "sets worker class and id in thread object" do
thread = subject.start_monitor_thread
expect(thread[:worker_class]).to eq subject.class.name
expect(thread[:worker_id]).to eq subject.id
end

it "adds a connection to the pool if there is only one" do
allow(ActiveRecord::Base).to receive(:connection_pool).and_return(pool)

expect(pool).to receive(:instance_variable_get).with(:@size).and_return(1)
expect(pool).to receive(:instance_variable_set).with(:@size, 2)
subject.start_monitor_thread
end
end

describe "#find_worker_thread_object" do
Expand Down

0 comments on commit 57b5da5

Please sign in to comment.