Introduce configureable query overheads and contexts in the test wrapper in preparation for timeout tests.
This commit is contained in:
parent
ea2965270c
commit
f077108a69
@ -1,6 +1,25 @@
|
||||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
EventedMysqlTest.new( 10 ) do |test|
|
||||
EventedMysqlTest.new( 10, "Evented, small overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 0.1
|
||||
test.run!
|
||||
end
|
||||
|
||||
EventedMysqlTest.new( 10, "Evented, medium overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 1
|
||||
test.run!
|
||||
end
|
||||
|
||||
EventedMysqlTest.new( 10, "Evented, large overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 3
|
||||
test.run!
|
||||
end
|
||||
|
||||
EventedMysqlTest.new( 10, "Evented, random overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = :random
|
||||
test.run!
|
||||
end
|
@ -7,17 +7,20 @@ class MysqlTest
|
||||
end
|
||||
|
||||
attr_accessor :queries,
|
||||
:context,
|
||||
:connections,
|
||||
:connection_signature,
|
||||
:start,
|
||||
:done,
|
||||
:c_async_query,
|
||||
:log_blocking_status
|
||||
:per_query_overhead
|
||||
|
||||
def initialize( queries )
|
||||
def initialize( queries, context = '' )
|
||||
@queries = queries
|
||||
@context = context
|
||||
@done = []
|
||||
@c_async_query = false
|
||||
@per_query_overhead = 3
|
||||
yield self if block_given?
|
||||
end
|
||||
|
||||
@ -28,11 +31,18 @@ class MysqlTest
|
||||
|
||||
def run!
|
||||
c_or_native_ruby_async_query do
|
||||
present_context if context?
|
||||
prepare
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def per_query_overhead=( overhead )
|
||||
@per_query_overhead = ( overhead == :random ) ? rand() : overhead
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def prepare
|
||||
raise NotImplemented
|
||||
end
|
||||
@ -55,7 +65,15 @@ class MysqlTest
|
||||
Time.now - @start
|
||||
end
|
||||
|
||||
protected
|
||||
def context?
|
||||
@context != ''
|
||||
end
|
||||
|
||||
def present_context
|
||||
log "#############################################"
|
||||
log "# #{@context}"
|
||||
log "#############################################"
|
||||
end
|
||||
|
||||
def c_or_native_ruby_async_query
|
||||
if @c_async_query
|
||||
@ -77,10 +95,10 @@ class EventedMysqlTest < MysqlTest
|
||||
|
||||
attr_accessor :sockets
|
||||
|
||||
def initialize( queries )
|
||||
def initialize( queries, context = '' )
|
||||
@sockets = []
|
||||
@connections = {}
|
||||
super( queries )
|
||||
super( queries, context )
|
||||
end
|
||||
|
||||
def setup( &block )
|
||||
@ -113,9 +131,11 @@ class EventedMysqlTest < MysqlTest
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def prepare
|
||||
@connections.each_value do |conn|
|
||||
conn.send_query( "select sleep(3)" )
|
||||
conn.send_query( "select sleep(#{@per_query_overhead})" )
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,8 +144,6 @@ class EventedMysqlTest < MysqlTest
|
||||
throw :END_EVENT_LOOP
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def done?
|
||||
@done.size == @queries
|
||||
end
|
||||
@ -136,10 +154,10 @@ class ThreadedMysqlTest < MysqlTest
|
||||
|
||||
attr_accessor :threads
|
||||
|
||||
def initialize( queries )
|
||||
def initialize( queries, context = '' )
|
||||
@connections = []
|
||||
@threads = []
|
||||
super( queries )
|
||||
super( queries, context )
|
||||
end
|
||||
|
||||
def setup( &block )
|
||||
@ -159,6 +177,8 @@ class ThreadedMysqlTest < MysqlTest
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def prepare
|
||||
with_logging "prepare" do
|
||||
@queries.times do |conn|
|
||||
@ -166,7 +186,7 @@ class ThreadedMysqlTest < MysqlTest
|
||||
|
||||
log "sending query on connection #{conn}"
|
||||
|
||||
c_or_native_async_query( @connections[conn], "select sleep(3)" ).each do |result|
|
||||
c_or_native_async_query( @connections[conn], "select sleep(#{@per_query_overhead})" ).each do |result|
|
||||
log "connection #{conn} done"
|
||||
end
|
||||
|
||||
|
@ -1,12 +1,53 @@
|
||||
require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
ThreadedMysqlTest.new( 10 ) do |test|
|
||||
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, small overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 0.1
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10 ) do |test|
|
||||
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, medium overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 1
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, large overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 3
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, native Ruby, random overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = :random
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, C, small overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 0.1
|
||||
test.c_async_query = true
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, C, medium overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 1
|
||||
test.c_async_query = true
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, C, large overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = 3
|
||||
test.c_async_query = true
|
||||
test.run!
|
||||
end
|
||||
|
||||
ThreadedMysqlTest.new( 10, "Threaded, C, random overhead" ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.per_query_overhead = :random
|
||||
test.c_async_query = true
|
||||
test.run!
|
||||
end
|
Loading…
Reference in New Issue
Block a user