Skip to content

Commit

Permalink
increase concurrent amount to catch a potential race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
pan committed Dec 2, 2022
1 parent 3f826dc commit 65a1fbc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions spec/granite/transactions/create_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ describe "#create" do
end

it "doesn't have a race condition on IDs" do
n = 1000
ids = Array(Int64).new(n)
channel = Channel(Int64).new

2.times do
n.times do
spawn do
parent = Parent.new(name: "Test Parent")
parent.save
channel.send(parent.id.not_nil!)
(id = parent.id) && channel.send(id)
end
end

id1 = channel.receive
id2 = channel.receive

id1.should_not eq id2
n.times { ids << channel.receive }
ids.uniq!.size.should eq n
end

describe "with a custom primary key" do
Expand Down

0 comments on commit 65a1fbc

Please sign in to comment.