Introduce configureable query overheads and contexts in the test wrapper in preparation for timeout tests.

This commit is contained in:
Lourens Naude 2008-09-08 17:45:00 +01:00
parent ea2965270c
commit f077108a69
3 changed files with 94 additions and 14 deletions

View File

@ -1,6 +1,25 @@
require File.dirname(__FILE__) + '/test_helper' 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.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! test.run!
end end

View File

@ -7,17 +7,20 @@ class MysqlTest
end end
attr_accessor :queries, attr_accessor :queries,
:context,
:connections, :connections,
:connection_signature, :connection_signature,
:start, :start,
:done, :done,
:c_async_query, :c_async_query,
:log_blocking_status :per_query_overhead
def initialize( queries ) def initialize( queries, context = '' )
@queries = queries @queries = queries
@context = context
@done = [] @done = []
@c_async_query = false @c_async_query = false
@per_query_overhead = 3
yield self if block_given? yield self if block_given?
end end
@ -28,11 +31,18 @@ class MysqlTest
def run! def run!
c_or_native_ruby_async_query do c_or_native_ruby_async_query do
present_context if context?
prepare prepare
yield yield
end end
end end
def per_query_overhead=( overhead )
@per_query_overhead = ( overhead == :random ) ? rand() : overhead
end
protected
def prepare def prepare
raise NotImplemented raise NotImplemented
end end
@ -55,7 +65,15 @@ class MysqlTest
Time.now - @start Time.now - @start
end end
protected def context?
@context != ''
end
def present_context
log "#############################################"
log "# #{@context}"
log "#############################################"
end
def c_or_native_ruby_async_query def c_or_native_ruby_async_query
if @c_async_query if @c_async_query
@ -77,10 +95,10 @@ class EventedMysqlTest < MysqlTest
attr_accessor :sockets attr_accessor :sockets
def initialize( queries ) def initialize( queries, context = '' )
@sockets = [] @sockets = []
@connections = {} @connections = {}
super( queries ) super( queries, context )
end end
def setup( &block ) def setup( &block )
@ -113,9 +131,11 @@ class EventedMysqlTest < MysqlTest
end end
end end
protected
def prepare def prepare
@connections.each_value do |conn| @connections.each_value do |conn|
conn.send_query( "select sleep(3)" ) conn.send_query( "select sleep(#{@per_query_overhead})" )
end end
end end
@ -124,8 +144,6 @@ class EventedMysqlTest < MysqlTest
throw :END_EVENT_LOOP throw :END_EVENT_LOOP
end end
protected
def done? def done?
@done.size == @queries @done.size == @queries
end end
@ -136,10 +154,10 @@ class ThreadedMysqlTest < MysqlTest
attr_accessor :threads attr_accessor :threads
def initialize( queries ) def initialize( queries, context = '' )
@connections = [] @connections = []
@threads = [] @threads = []
super( queries ) super( queries, context )
end end
def setup( &block ) def setup( &block )
@ -159,6 +177,8 @@ class ThreadedMysqlTest < MysqlTest
end end
end end
protected
def prepare def prepare
with_logging "prepare" do with_logging "prepare" do
@queries.times do |conn| @queries.times do |conn|
@ -166,7 +186,7 @@ class ThreadedMysqlTest < MysqlTest
log "sending query on connection #{conn}" 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" log "connection #{conn} done"
end end

View File

@ -1,12 +1,53 @@
require File.dirname(__FILE__) + '/test_helper' 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.setup{ Mysql.real_connect('localhost','root') }
test.per_query_overhead = 0.1
test.run! test.run!
end end
ThreadedMysqlTest.new( 10 ) do |test| ThreadedMysqlTest.new( 10, "Threaded, native Ruby, medium overhead" ) do |test|
test.setup{ Mysql.real_connect('localhost','root') } 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.c_async_query = true
test.run! test.run!
end end