Skip to content

Instantly share code, notes, and snippets.

View bdurand's full-sized avatar

Brian Durand bdurand

  • San Francisco, CA
View GitHub Profile
@bdurand
bdurand / row_lock_test_output.txt
Created October 18, 2012 17:10
ActiveRecord Row Lock Test Output
Current ActiveRecord code:
Selector Thread reports shared record exists
Thread 1 (0.8ms) BEGIN
Thread 1 running before_destroy callback
Thread 2 (0.6ms) BEGIN
Thread 2 running before_destroy callback
Selector Thread reports shared record exists
Thread 1 running before_destroy callback
Thread 2 running before_destroy callback
@bdurand
bdurand / row_lock_test.rb
Created October 18, 2012 17:07
ActiveRecord Row Lock Test
require 'rubygems'
require 'active_record'
require 'logger'
# Run as `ruby row_lock_test.rb [mysql|postgresql]` to see current Rails behavior when two processes
# try to destroy a record at the same time.
#
# Run as `ruby row_lock_test.rb [mysql|postgresql] patch` to see the behavior desired in pull request
# https://github.com/rails/rails/pull/7965
#
@bdurand
bdurand / counter_cache_test.rb
Created October 13, 2012 17:45
Demonstrate counter_cache/destroy callback race condition
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
class Widget < ActiveRecord::Base
connection.create_table table_name do |t|
t.string :name
t.integer :thing_count
end unless table_exists?
@bdurand
bdurand / benchmark_bundle.rb
Created May 10, 2012 16:15
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'bundler'
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,