Skip to content

Commit

Permalink
better concurrent increment test
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Feb 18, 2013
1 parent 286fd5d commit 873c48a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions script/generate-specs
Original file line number Diff line number Diff line change
Expand Up @@ -2012,10 +2012,12 @@ end}
SPECS['concurrent_increment'] = %{def increment_thread(name)
Thread.new do
s = new_store
1000.times do |i|
s.increment('counter', 1, :expires => false)
100.times do |i|
100.times do |j|
s.increment("counter\#{j}", 1, :expires => false)
Thread.pass if rand(1000) >= 995
end
s.store("\#{name}\#{i}", i.to_s, :expires => false)
Thread.pass if i % 100 == 0
end
s.close
end
Expand All @@ -2028,20 +2030,22 @@ it 'have atomic increment across multiple processes' do
a.join
b.join
c.join
1000.times do |i|
100.times do |i|
store["a\#{i}"].should == i.to_s
store["b\#{i}"].should == i.to_s
store["c\#{i}"].should == i.to_s
end
store.raw['counter'].should == 3000.to_s
100.times do |j|
store.raw["counter\#{j}"].should == 300.to_s
end
end}

SPECS['concurrent_create'] = %{def create_thread(name)
Thread.new do
s = new_store
1000.times do |i|
s[i.to_s].should == name if s.create(i.to_s, name, :expires => false)
Thread.pass if i % 100 == 0
Thread.pass if rand(100) >= 99
end
s.close
end
Expand Down
16 changes: 10 additions & 6 deletions spec/monetaspecs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17164,10 +17164,12 @@
def increment_thread(name)
Thread.new do
s = new_store
1000.times do |i|
s.increment('counter', 1, :expires => false)
100.times do |i|
100.times do |j|
s.increment("counter#{j}", 1, :expires => false)
Thread.pass if rand(1000) >= 995
end
s.store("#{name}#{i}", i.to_s, :expires => false)
Thread.pass if i % 100 == 0
end
s.close
end
Expand All @@ -17180,12 +17182,14 @@ def increment_thread(name)
a.join
b.join
c.join
1000.times do |i|
100.times do |i|
store["a#{i}"].should == i.to_s
store["b#{i}"].should == i.to_s
store["c#{i}"].should == i.to_s
end
store.raw['counter'].should == 3000.to_s
100.times do |j|
store.raw["counter#{j}"].should == 300.to_s
end
end
end

Expand All @@ -17197,7 +17201,7 @@ def create_thread(name)
s = new_store
1000.times do |i|
s[i.to_s].should == name if s.create(i.to_s, name, :expires => false)
Thread.pass if i % 100 == 0
Thread.pass if rand(100) >= 99
end
s.close
end
Expand Down

0 comments on commit 873c48a

Please sign in to comment.