1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-12-01 05:43:04 +00:00

feat: new background work process

This removes all previous dependencies on RabbitMQ and the need to run separate cron and requeueing processes.
هذا الالتزام موجود في:
Adam Cooke
2024-02-14 13:46:04 +00:00
ملتزم من قبل Adam Cooke
الأصل 044058d0f1
التزام dc8e895bfe
69 ملفات معدلة مع 1675 إضافات و1186 حذوفات

عرض الملف

@@ -0,0 +1,58 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe WorkerRole do
let(:locker_name) { "test" }
before do
allow(Postal).to receive(:locker_name).and_return(locker_name)
end
describe ".acquire" do
context "when there are no existing roles" do
it "returns :created" do
expect(WorkerRole.acquire("test")).to eq(:created)
end
end
context "when the current process holds a lock for a role" do
it "returns :renewed" do
create(:worker_role, role: "test", worker: "test", acquired_at: 1.minute.ago)
expect(WorkerRole.acquire("test")).to eq(:renewed)
end
end
context "when the role has become stale" do
it "returns :stolen" do
create(:worker_role, role: "test", worker: "another", acquired_at: 10.minute.ago)
expect(WorkerRole.acquire("test")).to eq(:stolen)
end
end
context "when the role is already locked by another worker" do
it "returns false" do
create(:worker_role, role: "test", worker: "another", acquired_at: 1.minute.ago)
expect(WorkerRole.acquire("test")).to eq(false)
end
end
end
describe ".release" do
context "when the role is locked by the current worker" do
it "deletes the role and returns true" do
role = create(:worker_role, role: "test", worker: "test")
expect(WorkerRole.release("test")).to eq(true)
expect(WorkerRole.find_by(id: role.id)).to be_nil
end
end
context "when the role is locked by another worker" do
it "does not delete the role and returns false" do
role = create(:worker_role, role: "test", worker: "another")
expect(WorkerRole.release("test")).to eq(false)
expect(WorkerRole.find_by(id: role.id)).to be_present
end
end
end
end