favgroups: fix race condition when adding posts to favgroups.

Adding or removing a post id to a favgroup's post_ids string is
non-atomic. Lock it to prevent simultaneous updates to the same favgroup
from clobbering each other.

Same bug as #3091.
This commit is contained in:
evazion
2017-11-26 10:31:28 -06:00
parent aeb24b6253
commit 80e115b600
2 changed files with 31 additions and 8 deletions

View File

@@ -813,6 +813,25 @@ class PostTest < ActiveSupport::TestCase
end
end
context "for a favgroup" do
setup do
@favgroup = FactoryGirl.create(:favorite_group, creator: @user)
@post = FactoryGirl.create(:post, :tag_string => "aaa favgroup:#{@favgroup.id}")
end
should "add the post to the favgroup" do
assert_equal(1, @favgroup.reload.post_count)
assert_equal(true, !!@favgroup.contains?(@post.id))
end
should "remove the post from the favgroup" do
@post.update(:tag_string => "-favgroup:#{@favgroup.id}")
assert_equal(0, @favgroup.reload.post_count)
assert_equal(false, !!@favgroup.contains?(@post.id))
end
end
context "for a pool" do
setup do
mock_pool_archive_service!