module BigBench
# The configuration is configured in the test reciepts and looks like this:
#
# BigBench.configure do |config|
# config.duration = 10.seconds,
# config.output = "test.ljson",
# config.users = 20,
# config.basic_auth = ['username', 'secret']
# end
#
# Single values can be set and retrieved like this:
#
# BigBench.config.duration = 20.minutes
# BigBench.config.duration # => 1200 (seconds)
#
# The following configuration values are possible - stared configurations need to be present:
#
# [duration*] How long will the benchmark take by default. This value can be overridden by every benchmark.
# [output*] The file where the results should be written to. Usually one takes the *.ljson format which is simply a file
# that contains a fully valid JSON object on every line. This makes it easy to process the results later on, because there's
# no need to parse the whole results JSON, which can get huge, at once.
# [users] How many users execute the benchmarks concurrently. This can be overridden by every benchmark and defaults to 1.
# [basic_auth] A basic authentication that is used by ALL requests. This can be overridden per fragment in every benchmark.
#
# BigBench.config.basic_auth = ['username', 'password']
#
module Configuration
DEFAULTS = {
:duration => 1.second,
:output => "result.ljson",
:users => 1,
:mode => :local,
:bot_checks_every => 1.minute
}
# Resets the config object
def self.reset!
@@config = nil
end
self.reset!
# Returns tor creates the config object
def self.config
@@config ||= OpenStruct.new(DEFAULTS)
end
end
# Configure the benchmark by supplying a hash of options like this:
#
# BigBench.configure do |config|
# config.duration = 10.seconds,
# config.output = "test.ljson",
# config.users = 20,
# config.basic_auth = ['username', 'secret']
# end
#
# Those values can then be set and retreived with BigBench.config.duration, ...
def self.configure
raise "No block to configure given" unless block_given?
yield(Configuration.config)
Configuration.config
end
# Set and retreive the config values like this:
#
# BigBench.config.duration # => 10.seconds
# BigBench.config.duration = 20.minutes
#
def self.config
Configuration.config
end
end