FIX: thread safety for active automation tracking (#27044)
This commit is contained in:
parent
7442cf3f62
commit
e90e6e8f86
|
@ -30,11 +30,11 @@ module ::DiscourseAutomation
|
||||||
USER_GROUP_MEMBERSHIP_THROUGH_BADGE_BULK_MODIFY_START_COUNT = 1000
|
USER_GROUP_MEMBERSHIP_THROUGH_BADGE_BULK_MODIFY_START_COUNT = 1000
|
||||||
|
|
||||||
def self.set_active_automation(id)
|
def self.set_active_automation(id)
|
||||||
@active_automation_id = id
|
Thread.current[:active_automation_id] = id
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_active_automation
|
def self.get_active_automation
|
||||||
@active_automation_id
|
Thread.current[:active_automation_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,20 @@ describe DiscourseAutomation::Triggerable do
|
||||||
|
|
||||||
fab!(:automation) { Fabricate(:automation, trigger: "foo") }
|
fab!(:automation) { Fabricate(:automation, trigger: "foo") }
|
||||||
|
|
||||||
|
describe "active automation thread safety" do
|
||||||
|
after { DiscourseAutomation.set_active_automation(nil) }
|
||||||
|
|
||||||
|
it "ensurese thread safety when setting automation id" do
|
||||||
|
DiscourseAutomation.set_active_automation(10)
|
||||||
|
|
||||||
|
thread = Thread.new { DiscourseAutomation.get_active_automation }
|
||||||
|
thread.join
|
||||||
|
expect(thread.value).to eq(nil)
|
||||||
|
|
||||||
|
expect(DiscourseAutomation.get_active_automation).to eq(10)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#setting" do
|
describe "#setting" do
|
||||||
before { DiscourseAutomation::Triggerable.add("foo") { setting :bar, :baz } }
|
before { DiscourseAutomation::Triggerable.add("foo") { setting :bar, :baz } }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue