Fix single Redis connection being used across all threads (#18135)
* Fix single Redis connection being used across all Sidekiq threads * Fix tests
This commit is contained in:
parent
9bf04db23a
commit
3917353645
44 changed files with 243 additions and 124 deletions
|
@ -14,7 +14,7 @@ RSpec.describe AfterBlockService, type: :service do
|
|||
let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
|
||||
|
||||
before do
|
||||
Redis.current.del(home_timeline_key)
|
||||
redis.del(home_timeline_key)
|
||||
end
|
||||
|
||||
it "clears account's statuses" do
|
||||
|
@ -23,7 +23,7 @@ RSpec.describe AfterBlockService, type: :service do
|
|||
FeedManager.instance.push_to_home(account, other_account_reblog)
|
||||
|
||||
expect { subject }.to change {
|
||||
Redis.current.zrange(home_timeline_key, 0, -1)
|
||||
redis.zrange(home_timeline_key, 0, -1)
|
||||
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||
end
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ RSpec.describe AfterBlockService, type: :service do
|
|||
let(:list_timeline_key) { FeedManager.instance.key(:list, list.id) }
|
||||
|
||||
before do
|
||||
Redis.current.del(list_timeline_key)
|
||||
redis.del(list_timeline_key)
|
||||
end
|
||||
|
||||
it "clears account's statuses" do
|
||||
|
@ -42,7 +42,7 @@ RSpec.describe AfterBlockService, type: :service do
|
|||
FeedManager.instance.push_to_list(list, other_account_reblog)
|
||||
|
||||
expect { subject }.to change {
|
||||
Redis.current.zrange(list_timeline_key, 0, -1)
|
||||
redis.zrange(list_timeline_key, 0, -1)
|
||||
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
|
|||
let(:status2) { PostStatusService.new.call(alice, text: 'Another status') }
|
||||
|
||||
before do
|
||||
allow(Redis.current).to receive_messages(publish: nil)
|
||||
allow(redis).to receive_messages(publish: nil)
|
||||
|
||||
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
||||
|
||||
|
@ -40,11 +40,11 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
|
|||
end
|
||||
|
||||
it 'notifies streaming API of followers' do
|
||||
expect(Redis.current).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
|
||||
expect(redis).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
|
||||
end
|
||||
|
||||
it 'notifies streaming API of public timeline' do
|
||||
expect(Redis.current).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
|
||||
expect(redis).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
|
||||
end
|
||||
|
||||
it 'sends delete activity to followers' do
|
||||
|
|
|
@ -18,7 +18,7 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
ProcessMentionsService.new.call(status)
|
||||
ProcessHashtagsService.new.call(status)
|
||||
|
||||
allow(Redis.current).to receive(:publish)
|
||||
allow(redis).to receive(:publish)
|
||||
|
||||
subject.call(status)
|
||||
end
|
||||
|
@ -40,13 +40,13 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
end
|
||||
|
||||
it 'is broadcast to the hashtag stream' do
|
||||
expect(Redis.current).to have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(Redis.current).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
|
||||
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
|
||||
end
|
||||
|
||||
it 'is broadcast to the public stream' do
|
||||
expect(Redis.current).to have_received(:publish).with('timeline:public', anything)
|
||||
expect(Redis.current).to have_received(:publish).with('timeline:public:local', anything)
|
||||
expect(redis).to have_received(:publish).with('timeline:public', anything)
|
||||
expect(redis).to have_received(:publish).with('timeline:public:local', anything)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,8 +66,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
end
|
||||
|
||||
it 'is not broadcast publicly' do
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -84,8 +84,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
end
|
||||
|
||||
it 'is not broadcast publicly' do
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,8 +105,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
|
|||
end
|
||||
|
||||
it 'is not broadcast publicly' do
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
||||
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ RSpec.describe MuteService, type: :service do
|
|||
let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
|
||||
|
||||
before do
|
||||
Redis.current.del(home_timeline_key)
|
||||
redis.del(home_timeline_key)
|
||||
end
|
||||
|
||||
it "clears account's statuses" do
|
||||
|
@ -20,7 +20,7 @@ RSpec.describe MuteService, type: :service do
|
|||
FeedManager.instance.push_to_home(account, other_account_status)
|
||||
|
||||
expect { subject }.to change {
|
||||
Redis.current.zrange(home_timeline_key, 0, -1)
|
||||
redis.zrange(home_timeline_key, 0, -1)
|
||||
}.from([status.id.to_s, other_account_status.id.to_s]).to([other_account_status.id.to_s])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ RSpec.describe PrecomputeFeedService, type: :service do
|
|||
|
||||
subject.call(account)
|
||||
|
||||
expect(Redis.current.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
|
||||
expect(redis.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
|
||||
end
|
||||
|
||||
it 'does not raise an error even if it could not find any status' do
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe PrecomputeFeedService, type: :service do
|
|||
|
||||
subject.call(account)
|
||||
|
||||
expect(Redis.current.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to eq nil
|
||||
expect(redis.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue