Module: RRRSpec

Defined in:
lib/rrrspec.rb,
lib/rrrspec/client/cli.rb,
lib/rrrspec/redis_models.rb,
lib/rrrspec/configuration.rb,
lib/rrrspec/client/support.rb,
lib/rrrspec/client/version.rb,
lib/rrrspec/client/rspec_runner.rb,
lib/rrrspec/client/slave_runner.rb,
lib/rrrspec/client/configuration.rb

Defined Under Namespace

Modules: ActiveTaskset, ArbiterQueue, Client, DispatcherQueue, PersisterQueue, StatisticsUpdaterQueue, TasksetEstimation Classes: Configuration, Slave, Task, Taskset, TimedLogger, Trial, Worker, WorkerLog

Constant Summary collapse

DEFAULT_CONFIG_FILES =
[
  home_rrrspec,
  '.rrrspec',
  '.rrrspec-local'
].compact

Class Method Summary collapse

Class Method Details

.configurationObject



19
20
21
# File 'lib/rrrspec.rb', line 19

def configuration
  @configuration
end

.configuration=(configuration) ⇒ Object



23
24
25
# File 'lib/rrrspec.rb', line 23

def configuration=(configuration)
  @configuration = configuration
end

.configure(type = nil) ⇒ Object



27
28
29
30
31
# File 'lib/rrrspec.rb', line 27

def configure(type=nil)
  if type == nil || type == configuration.type
    yield configuration
  end
end

.convert_if_present(h, key) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/rrrspec/redis_models.rb', line 5

def self.convert_if_present(h, key)
  if h[key].present?
    h[key] = yield h[key]
  else
    h[key] = nil
  end
end

.flushredisObject



49
50
51
52
53
54
# File 'lib/rrrspec.rb', line 49

def flushredis
  Thread.list.each do |thread|
    thread[:redis] = nil
    thread[:pid] = nil
  end
end

.hostnameObject



60
61
62
# File 'lib/rrrspec.rb', line 60

def hostname
  @hostname ||= Socket.gethostname
end

.hostname=(hostname) ⇒ Object



64
65
66
# File 'lib/rrrspec.rb', line 64

def hostname=(hostname)
  @hostname = hostname
end

.loggerObject



92
93
94
# File 'lib/rrrspec.rb', line 92

def logger
  @logger ||= Logger.new(STDERR)
end

.logger=(logger) ⇒ Object



96
97
98
# File 'lib/rrrspec.rb', line 96

def logger=(logger)
  @logger = logger
end

.make_key(*args) ⇒ Object



56
57
58
# File 'lib/rrrspec.rb', line 56

def make_key(*args)
  args.join(':')
end

.pacemaker(obj, time, margin) ⇒ Object



68
69
70
71
72
73
# File 'lib/rrrspec.rb', line 68

def pacemaker(obj, time, margin)
  loop do
    obj.heartbeat(time)
    sleep time - margin
  end
end

.redisObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rrrspec.rb', line 33

def redis
  # After the process is daemonized, the redis instance is in invalid state.
  # We avoid using such instance by checking the PID.
  if not Thread.current[:pid] or Thread.current[:pid] != Process.pid
    Thread.current[:redis] = nil
    Thread.current[:pid] = Process.pid
  end

  # It is probable that if two other threads shares one redis connection
  # one thread blocks the other thread. We avoid this by using separate
  # connections.
  Thread.current[:redis] ||= begin
                               configuration.redis.dup
                             end
end

.setup(configuration, config_files) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/rrrspec.rb', line 83

def setup(configuration, config_files)
  RRRSpec.configuration = configuration
  files = config_files
  files += ENV['RRRSPEC_CONFIG_FILES'].split(':') if ENV['RRRSPEC_CONFIG_FILES']
  files += DEFAULT_CONFIG_FILES if files.empty?
  RRRSpec.configuration.load_files(files)
  exit 1 unless RRRSpec.configuration.check_validity
end