Permalink
Browse files

better concurrent increment test

  • Loading branch information...
1 parent 286fd5d commit 873c48a4932878017d6cb4e40f6a1430f0528d10 @minad committed Feb 18, 2013
Showing with 20 additions and 12 deletions.
  1. +10 −6 script/generate-specs
  2. +10 −6 spec/monetaspecs.rb
View
@@ -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
@@ -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
View
@@ -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
@@ -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
@@ -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

0 comments on commit 873c48a

Please sign in to comment.