FIX: `DiscourseRedis::FallbackHandler` not restricting number of threads spawned.

This commit is contained in:
Guo Xiang Tan 2016-04-15 17:05:03 +08:00
parent 9e50f36c50
commit 862b4fc9da
No known key found for this signature in database
GPG Key ID: 19C321C8952B0F72
2 changed files with 10 additions and 2 deletions

View File

@ -18,7 +18,7 @@ class DiscourseRedis
def verify_master
synchronize do
return if @running && !recently_checked?
return if @running || recently_checked?
@running = true
end
@ -58,7 +58,7 @@ class DiscourseRedis
def recently_checked?
if @last_checked
Time.zone.now > (@last_checked + 5.seconds)
Time.zone.now <= (@last_checked + 5.seconds)
else
false
end

View File

@ -96,6 +96,14 @@ describe DiscourseRedis do
fallback_handler.master = true
end
end
it "should restrict the number of checks" do
expect { fallback_handler.verify_master }.to change { Thread.list.count }.by(1)
expect(fallback_handler.master).to eq(true)
fallback_handler.master = false
expect { fallback_handler.verify_master }.to_not change { Thread.list.count }
end
end
end
end