-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
58 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
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
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe Que::Adapters::ActiveRecordWithLock do | ||
subject(:adapter) do | ||
described_class.new(job_connection_pool: JobRecord.connection_pool, | ||
lock_connection_pool: LockDatabaseRecord.connection_pool) | ||
end | ||
|
||
around do |example| | ||
Que.adapter.tap do |old_adapter| | ||
# We need this to avoid errors related to prepared statements | ||
if old_adapter.class != described_class | ||
Que.adapter = adapter | ||
example.run | ||
Que.adapter = old_adapter | ||
else | ||
example.run | ||
end | ||
end | ||
end | ||
|
||
before do | ||
described_class::FindJobHitTotal.values.each { |labels, _| labels.clear } | ||
end | ||
|
||
context "with enqueued jobs" do | ||
before do | ||
10.times do | ||
FakeJob.enqueue(1) | ||
end | ||
end | ||
|
||
it "sets correct metric values" do | ||
with_workers(5) { wait_for_jobs_to_be_worked } | ||
expect(described_class::FindJobHitTotal.values[{ :queue => "default", :job_hit => "true" }]).to eq(10.0) | ||
end | ||
end | ||
|
||
describe ".lock_job_with_lock_database" do | ||
subject(:lock_job) { adapter.lock_job_with_lock_database("default", 0) } | ||
|
||
context "with no jobs enqueued" do | ||
it "exists the loop and sets correct metric values" do | ||
expect(QueJob.count).to eq(0) | ||
locked_job = lock_job | ||
expect(locked_job).to eq([]) | ||
expect(described_class::FindJobHitTotal.values[{ :queue => "default", :job_hit => "true" }]).to eq(0.0) | ||
end | ||
end | ||
end | ||
end |
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