Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a connection to the pool if there is only one for embedded ansible #16477

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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