discourse/spec/jobs/sync_acls_for_uploads_spec.rb
Martin Brennan 9f2138dc92
FEATURE: Add a sidekiq job for syncing S3 ACLs (#16449)
Sometimes we need to update a _lot_ of ACLs on S3 (such as when secure media
is enabled), and since it takes ~1s per upload to update the ACL, this is
best spread out over many jobs instead of having to do the whole thing serially.

In future, it will be better to have a job that can be run based on
a column on uploads (e.g. acl_stale) so we can track progress, similar
to how we can set the baked_version to nil to rebake posts.
2022-04-12 14:26:42 +10:00

32 lines
699 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Jobs::SyncAclsForUploads do
let(:upload1) { Fabricate(:upload) }
let(:upload2) { Fabricate(:upload) }
let(:upload3) { Fabricate(:secure_upload) }
let(:upload_ids) { [upload1.id, upload2.id, upload3.id] }
def run_job
described_class.new.execute(upload_ids: upload_ids)
end
it "does nothing if not using external storage" do
Upload.expects(:where).never
run_job
end
context "external storage enabled" do
before do
setup_s3
stub_s3_store
end
it "runs update_upload_ACL for each upload" do
Discourse.store.expects(:update_upload_ACL).times(3)
run_job
end
end
end