spec/monetaspecs.rb in moneta-0.7.11 vs spec/monetaspecs.rb in moneta-0.7.12
- old
+ new
@@ -17140,9 +17140,59 @@
store.increment('inckey')
end.to raise_error(NotImplementedError)
end
end
+#################### concurrent_increment ####################
+
+shared_examples_for 'concurrent_increment' do
+ def increment_thread(name)
+ Thread.new do
+ s = new_store
+ 1000.times do |i|
+ s.increment('counter')
+ s.store("#{name}#{i}", i.to_s, :expires => false)
+ sleep 0.01 if i % 100 == 0
+ end
+ s.close
+ end
+ end
+
+ it 'have atomic increment across multiple processes' do
+ a = increment_thread('a')
+ b = increment_thread('b')
+ a.join
+ b.join
+ 1000.times do |i|
+ store["a#{i}"].should == i.to_s
+ store["b#{i}"].should == i.to_s
+ end
+ store.raw['counter'].should == 2000.to_s
+ end
+end
+
+#################### concurrent_create ####################
+
+shared_examples_for 'concurrent_create' do
+ def create_thread(name)
+ a = 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)
+ sleep 0.01 if i % 100 == 0
+ end
+ s.close
+ end
+ end
+
+ it 'have atomic create across multiple processes' do
+ a = create_thread('a')
+ b = create_thread('b')
+ a.join
+ b.join
+ end
+end
+
#################### increment ####################
shared_examples_for 'increment' do
it 'initializes in #increment with 1' do
store.key?('inckey').should be_false