Skip to content

Commit

Permalink
fix(ci): allow tests to run in docker (#805)
Browse files Browse the repository at this point in the history
* tests: allow overwriting redis/toxiproxy url

* chore: appease rubocop
  • Loading branch information
Earlopain committed Aug 17, 2023
1 parent cea0c7b commit 36ffe8f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler: 2.4.12
bundler-cache: true
- run: bin/rspec --require spec_helper --tag ~perf
- run: >-
REDIS_HOST=localhost
TOXI_REDIS_URL=toxiproxy:21212
TOXI_PROXY_HOST=http://toxiproxy:8474
bin/rspec --require spec_helper --tag ~perf
8 changes: 4 additions & 4 deletions spec/integration/until_and_while_executing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
RSpec.describe "SidekiqUniqueJobs::Lock::UntilAndWhileExecuting" do
before do
digests.delete_by_pattern("*")
toxic_redis_url = ENV["CI"] ? "toxiproxy:21212" : "localhost:21212"
redis_url = ENV["CI"] ? ENV.fetch("REDIS_URL", nil) : "localhost:6379"
toxi_redis_url = ENV.fetch("TOXI_REDIS_URL", "localhost:21212")
redis_url = ENV.fetch("REDIS_URL", "localhost:6379")

Toxiproxy.host = "http://toxiproxy:8474" if ENV["CI"]
Toxiproxy.host = ENV.fetch("TOXI_PROXY_HOST", nil)
Toxiproxy.populate([
{
name: :redis,
listen: toxic_redis_url,
listen: toxi_redis_url,
upstream: redis_url,
},
])
Expand Down
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/digests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@

describe "#page" do
include_context "with a regular job"

it "returns the correct amount of results" do
total_size, _cursor, locks = digests.page(cursor: 0, page_size: 100, pattern: "*")

expect(locks.size).to be(total_size)
expect(locks.size).to be(expected_keys.size)
expect(expected_keys.keys).to match_array(locks.map(&:key).map(&:digest))
expect(expected_keys.keys).to match_array(locks.map { |lock| lock.key.digest })
end
end
end
3 changes: 1 addition & 2 deletions spec/sidekiq_unique_jobs/on_conflict/reject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
end

before do
allow(strategy).to receive(:deadset).and_return(deadset)
allow(strategy).to receive(:payload).and_return(payload)
allow(strategy).to receive_messages(deadset: deadset, payload: payload)
end

describe "#replace?" do
Expand Down
9 changes: 3 additions & 6 deletions spec/sidekiq_unique_jobs/on_conflict/replace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
let(:jid) { "bogus" }

before do
allow(strategy).to receive(:delete_job_by_digest).and_return(jid)
allow(strategy).to receive_messages(delete_job_by_digest: jid, delete_lock: 9)
allow(strategy).to receive(:log_info).and_call_original
allow(strategy).to receive(:delete_lock).and_return(9)
end

it "logs important information" do
Expand All @@ -50,9 +49,8 @@
let(:jid) { "bogus" }

before do
allow(strategy).to receive(:delete_job_by_digest).and_return(jid)
allow(strategy).to receive_messages(delete_job_by_digest: jid, delete_lock: nil)
allow(strategy).to receive(:log_info).and_call_original
allow(strategy).to receive(:delete_lock).and_return(nil)
end

it "logs important information" do
Expand All @@ -68,9 +66,8 @@
let(:block) { nil }

before do
allow(strategy).to receive(:delete_job_by_digest).and_return(jid)
allow(strategy).to receive_messages(delete_job_by_digest: jid, delete_lock: nil)
allow(strategy).to receive(:log_info).and_call_original
allow(strategy).to receive(:delete_lock).and_return(nil)
end

it "does not call block" do
Expand Down
8 changes: 2 additions & 6 deletions spec/sidekiq_unique_jobs/orphans/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
before do
allow(SidekiqUniqueJobs::Orphans::Observer).to receive(:new).and_return(observer)

allow(described_class).to receive(:task).and_return(task)
allow(described_class).to receive_messages(task: task, log_info: nil)
allow(task).to receive(:add_observer).with(observer)
allow(task).to receive(:execute)

allow(described_class).to receive(:log_info).and_return(nil)
end

context "when registered?" do
Expand Down Expand Up @@ -72,11 +70,9 @@
before do
allow(SidekiqUniqueJobs::Orphans::Observer).to receive(:new).and_return(observer)

allow(described_class).to receive(:task).and_return(task)
allow(described_class).to receive_messages(task: task, log_info: nil)
allow(task).to receive(:add_observer).with(observer)
allow(task).to receive(:execute)

allow(described_class).to receive(:log_info).and_return(nil)
end

context "when unregistered?" do
Expand Down
4 changes: 1 addition & 3 deletions spec/sidekiq_unique_jobs/orphans/reaper_resurrector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
end

before do
allow(described_class).to receive(:task).and_return(task)
allow(described_class).to receive_messages(task: task, log_info: nil)
allow(task).to receive(:execute)

allow(described_class).to receive(:log_info).and_return(nil)
end

context "when resurrector is disabled" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

before do
allow(lock).to receive(:locked?).and_return(initially_locked?, locked?)
allow(lock).to receive(:unlock).and_return(true)
allow(lock).to receive(:delete).and_return(true)
allow(lock).to receive_messages(unlock: true, delete: true)
allow(callback).to receive(:call).and_call_original
allow(block).to receive(:call).and_call_original
allow(lock).to receive(:log_warn)
Expand Down
3 changes: 2 additions & 1 deletion spec/support/sidekiq_meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
RSpec.configure do |config|
config.before do |example|
redis_db = example.metadata.fetch(:redis_db, 0)
redis_url = "redis://localhost/#{redis_db}"
redis_host = ENV.fetch("REDIS_HOST", "localhost")
redis_url = "redis://#{redis_host}/#{redis_db}"
redis_options = { url: redis_url, driver: :ruby }
# redis = Sidekiq::RedisConnection.create(redis_options)

Expand Down

0 comments on commit 36ffe8f

Please sign in to comment.