Skip to content

Commit

Permalink
Runs the entire test on TestAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
mereghost committed Jun 26, 2024
1 parent bfe812c commit b3e1a6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class << self
def debounce(storage)
key = "sync-#{storage.short_provider_type}-#{storage.id}"
timestamp = RequestStore.store[key]

return false if timestamp.present? && (timestamp + SINGLE_THREAD_DEBOUNCE_TIME) > Time.current

result = set(wait: 5.seconds).perform_later(storage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,24 @@
RSpec.describe Storages::AutomaticallyManagedStorageSyncJob, type: :job do
let(:managed_nextcloud) { create(:nextcloud_storage_configured, :as_automatically_managed) }

describe ".debounce", with_good_job: [described_class] do
describe ".debounce" do
context "when has been debounced by other thread" do
it "does not change the number of enqueued jobs" do
expect(GoodJob::Job.count).to eq(0)
expect(described_class.perform_later(managed_nextcloud).successfully_enqueued?).to be(true)
expect(described_class.perform_later(managed_nextcloud)).to be(false)
expect(GoodJob::Job.count).to eq(1)
expect(performed_jobs.count).to eq(0)
expect(described_class.debounce(managed_nextcloud).successfully_enqueued?).to be(true)
expect(described_class.debounce(managed_nextcloud)).to be(false)
expect(enqueued_jobs.count).to eq(1)

expect { described_class.debounce(managed_nextcloud) }.not_to change(GoodJob::Job, :count)
expect { described_class.debounce(managed_nextcloud) }.not_to change(enqueued_jobs, :count)
end
end

context "when has not been debounced by other thread" do
before { RequestStore.delete("sync-nextcloud-#{managed_nextcloud.id}") }

it "schedules a job" do
expect { described_class.debounce(managed_nextcloud) }.to change(GoodJob::Job, :count).from(0).to(1)
expect { described_class.debounce(managed_nextcloud) }.to change(enqueued_jobs, :count).from(0).to(1)
end

# it "tries to schedule once when called 1000 times in a short period of time" do
# expect_any_instance_of(ActiveJob::ConfiguredJob)
# .to receive(:perform_later).once.and_call_original
#
# expect do
# 1000.times { described_class.debounce(managed_nextcloud) }
# end.to change(GoodJob::Job, :count).from(0).to(1)
# end
end
end

Expand Down

0 comments on commit b3e1a6a

Please sign in to comment.