Replace couchbase counters with drb version

This commit is contained in:
2014-08-05 17:49:16 +02:00
parent c0c25673bf
commit 99a9536c68
20 changed files with 400 additions and 282 deletions
-51
View File
@@ -1,51 +0,0 @@
# This is a non thread safe replacement for the
# couchbase counter mechanism since every test needs
# a clean start and Hash#clear is soooo much faster than
# a couchbase bucket flush
class InMemoryQCounter
attr_reader :store
def initialize
@store = {}
end
def get(key, options = {})
store[key]
end
def set(key, value)
store[key] = value
end
def incr(key, options = {})
# store[key] ||= options[:initial].to_i
# store[key] += 1
if store[key]
store[key] += 1
else
store[key] = options[:initial].to_i
end
end
def decr(key, options = {})
# store[key] ||= options[:initial].to_i
# store[key] -= 1
if store[key]
store[key] -= 1
else
store[key] = options[:initial].to_i
end
end
def flush
store.clear
end
end
=begin Make drb server
require 'drb'
DRb.start_service 'druby://:9000', InMemoryQCounter.new
puts "Counter server running at #{DRb.uri}"
trap("INT") { DRb.stop_service }
DRb.thread.join
=end
@@ -14,6 +14,7 @@ module Matchers
def initialize(user_id)
@user_id = user_id
@user_id = @user_id.id if @user_id.is_a?(User)
end
def matches?(block)
@@ -24,8 +25,9 @@ module Matchers
Qwaiter.broadcaster = old_broadcaster
relevant_broadcasts = test_broadcaster.broadcasts.select{|b| b[:channel] =~ /^\/user\/#{@user_id}/ && b[:data][:event] == @message}
@failure_message = "User #{@user_id} did not receive any broadcasts" and return false if relevant_broadcasts.empty?
@failure_debug_content = "was #{relevant_broadcasts.map{|b| b[:data][:data].inspect}.join(" and ")}"
relevant_broadcasts.any?{|b| @target_object === b[:data][:data]}
relevant_broadcasts.any? { |b| @target_object === b[:data][:data] }
end
def message(msg)
@@ -39,7 +41,7 @@ module Matchers
end
def failure_message
"user #{@user_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
@failure_message || "user #{@user_id} did not receive broadcast #{@message} with #{@target_object.inspect} #{@failure_debug_content}"
end
def supports_block_expectations?; true; end
end