This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT dwelled_recipe_id as recipe_id, query, query_rank | |
FROM ( | |
SELECT *, ROW_NUMBER() OVER(PARTITION BY dwelled_recipe_id ORDER BY session_count desc) as query_rank | |
FROM ( | |
SELECT dwelled_recipe_id, query, count(*) as session_count | |
FROM global_dwh.search_session_stats | |
WHERE region = 'ES' AND dwelled_recipe_id IS NOT NULL AND started_at > '2022-01-01 00:00:00.000+00' | |
GROUP BY 1, 2 | |
) session_count_summary | |
) ranked_session_count_summary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "causes deadlock?", use_transactional_tests: false do | |
device = create(:device, push_notification_subscriptions: %w(cooksnap_reminder mentioned_in_comment moderation_message)) | |
threads = [] | |
threads << Thread.new do | |
puts "START THREAD 1" | |
DeviceCreationService.run( | |
device.user, { | |
access_token: device.access_token, | |
token: device.token, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "causes deadlock?", use_transactional_tests: false do | |
device = create(:device, push_notification_subscriptions: %w(cooksnap_reminder mentioned_in_comment moderation_message)) | |
threads = [] | |
threads << Thread.new do | |
puts "START THREAD 1" | |
DeviceCreationService.run( | |
device.user, { | |
access_token: device.access_token, | |
token: device.token, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up `use_transactional_tests: false` as a tag that turns off transactional tests for the spec. | |
# Wrapping each spec in a transaction prevents concurrent transactions within the spec. | |
# See https://guides.rubyonrails.org/testing.html#testing-parallel-transactions | |
RSpec.configure do |config| | |
config.around(:each, use_transactional_tests: false) do |example| | |
self.use_transactional_tests = false | |
example.run | |
self.use_transactional_tests = true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I tried a few test scenarios to see when a transaction might read a value that is stale. | |
# | |
# * * * | |
# | |
# Test 1 | |
# 1. Transaction 1 gets count from recipe: 0 | |
# 2. Transaction 2 gets count from recipe: 0 | |
# 3. Transaction 2 updates count: 666 | |
# 4. Transaction 1 gets count: 0 | |
# 5. Transaction 1 commits |