diff --git a/app/models/embedded_ansible_worker.rb b/app/models/embedded_ansible_worker.rb index 810f2151415..66a8da41539 100644 --- a/app/models/embedded_ansible_worker.rb +++ b/app/models/embedded_ansible_worker.rb @@ -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) @@ -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 diff --git a/spec/models/embedded_ansible_worker_spec.rb b/spec/models/embedded_ansible_worker_spec.rb index bf187c84078..d126797efbc 100644 --- a/spec/models/embedded_ansible_worker_spec.rb +++ b/spec/models/embedded_ansible_worker_spec.rb @@ -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