Skip to content

Instantly share code, notes, and snippets.

View ollieh-m's full-sized avatar

Ollie Haydon-Mulligan ollieh-m

  • Bristol
View GitHub Profile
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
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,
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,
# 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
# 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