Class: DeepTest::Distributed::TestServer

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/distributed/test_server.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  :work_dir => "/tmp",
  :uri => "drubyall://:4022",
  :number_of_workers => 2
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TestServer

Returns a new instance of TestServer.



10
11
12
# File 'lib/deep_test/distributed/test_server.rb', line 10

def initialize(config)
  @config = config
end

Class Method Details

.connect(options) ⇒ Object



77
78
79
80
# File 'lib/deep_test/distributed/test_server.rb', line 77

def self.connect(options)
  servers = DRbObject.new_with_uri(options.distributed_server).servers
  MultiTestServerProxy.new(options, servers)
end

.parse_args(args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/deep_test/distributed/test_server.rb', line 52

def self.parse_args(args)
  options = DeepTest::Distributed::TestServer::DEFAULT_CONFIG.dup
  OptionParser.new do |opts|
    opts.banner = "Usage: deep_test test_server [options]"

    opts.on("--work_dir PATH", "Absolute path to keep mirror working copies at") do |v|
      options[:work_dir] = v
    end

    opts.on("--uri URI", "DRb URI to bind server to") do |v|
      options[:uri] = v
    end

    opts.on("--number_of_workers NUM", "Number of workers to start when running tests") do |v|
      options[:number_of_workers] = v.to_i
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end.parse(args)
  options
end

.start(config) ⇒ Object



45
46
47
48
49
50
# File 'lib/deep_test/distributed/test_server.rb', line 45

def self.start(config)
  server = DeepTest::Distributed::TestServer.new(config)
  DRb.start_service(config[:uri], server)
  DeepTest.logger.info "TestServer listening at #{DRb.uri}"
  DRb.thread.join
end

Instance Method Details

#configObject



37
38
39
# File 'lib/deep_test/distributed/test_server.rb', line 37

def config
  @config
end

#serversObject



41
42
43
# File 'lib/deep_test/distributed/test_server.rb', line 41

def servers
  [DRbObject.new_with_uri(DRb.uri)]
end

#spawn_worker_server(options) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/deep_test/distributed/test_server.rb', line 14

def spawn_worker_server(options)
  DeepTest.logger.debug("mirror spawn_worker_server for #{options.origin_hostname}")
  RemoteWorkerServer.start(URI.parse(@config[:uri]).host,
                           options.mirror_path(@config[:work_dir]),
                           TestServerWorkers.new(options, @config, DRbClientConnectionInfo.new),
                           options)
end

#statusObject



22
23
24
25
26
27
28
# File 'lib/deep_test/distributed/test_server.rb', line 22

def status
  TestServerStatus.new(
    DRb.uri, 
    @config[:number_of_workers],
    RemoteWorkerServer.running_server_count
  )
end

#sync(options) ⇒ Object



30
31
32
33
34
35
# File 'lib/deep_test/distributed/test_server.rb', line 30

def sync(options)
  DeepTest.logger.debug "mirror sync for #{options.origin_hostname}"
  path = options.mirror_path(@config[:work_dir])
  DeepTest.logger.debug "Syncing #{options.sync_options[:source]} to #{path}"
  RSync.sync(DRbClientConnectionInfo.new, options, path)
end