Skip to content

Instantly share code, notes, and snippets.

@soulcutter soulcutter/test.rb
Created Mar 8, 2019

Embed
What would you like to do?
create_or_find_by sequence exhaustion
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "rails")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class BugTest < Minitest::Test
def test_primary_key_growth
post = Post.create!
2_500_000_000.times { Post.create_or_find_by(id: post.id) }
# This fails
# Failure:
# BugTest#test_primary_key_growth [create_or_find_by.rb:56]:
# Expected: 2
# Actual: #<Comment id: 3, post_id: 2>
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.