Last active
June 20, 2017 08:16
-
-
Save audy/4bf963ee473dc2c113ee30c325291bb4 to your computer and use it in GitHub Desktop.
This file contains 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
source 'https://rubygems.org' | |
gem 'activerecord' | |
gem 'blamer' | |
gem 'pg' | |
gem 'pry' | |
gem 'parallel' |
This file contains 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
require 'bundler' | |
Bundler.require | |
class Foo < ActiveRecord::Base | |
establish_connection adapter: 'postgresql', database: 'test_blamer' | |
connection.create_table table_name, force: true do |t| | |
t.string :name | |
t.userstamps | |
end | |
end | |
class Foo < ActiveRecord::Base | |
end | |
class User | |
cattr_accessor :current_user | |
attr_accessor :id | |
def initialize kwargs | |
@id = kwargs.fetch(:id) | |
end | |
def id | |
@id | |
end | |
end | |
puts 'testing single threaded' | |
Parallel.each((0..100), in_threads: 1) do |i| | |
expected_id = rand(0..1) | |
User.current_user = User.new id: expected_id | |
foo = Foo.create! | |
foo.reload | |
fail "#{i} -> expected #{foo.created_by} to equal #{expected_id}" unless foo.created_by == expected_id | |
end | |
puts 'testing 2-threaded' | |
Parallel.each((0..100), in_threads: 2) do |i| | |
expected_id = rand(0..1) | |
User.current_user = User.new id: expected_id | |
foo = Foo.create! | |
foo.reload | |
fail "#{i} -> expected #{foo.created_by} to equal #{expected_id}" unless foo.created_by == expected_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment