Class: DeepTest::Distributed::MultiTestServerProxy

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

Defined Under Namespace

Classes: WorkerServerProxy

Instance Method Summary collapse

Constructor Details

#initialize(options, slaves) ⇒ MultiTestServerProxy

Returns a new instance of MultiTestServerProxy.



5
6
7
8
9
# File 'lib/deep_test/distributed/multi_test_server_proxy.rb', line 5

def initialize(options, slaves)
  DeepTest.logger.debug "MultiTestServerProxy#initialize #{slaves.length} slaves"
  @slave_controller = DispatchController.new(options, slaves)
  @slaves = slaves
end

Instance Method Details

#multi_push_sync(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/deep_test/distributed/multi_test_server_proxy.rb', line 27

def multi_push_sync(options)
  puts "Syncing..."
  sync_start = Time.now
  
  threads = @slaves.map do |slave|
    Thread.new do
      Thread.current[:receiver] = slave
      Timeout.timeout(options.timeout_in_seconds) do
        RSync.sync(Struct.new(:address).new(URI::parse(slave.__drburi).host), options, options.mirror_path(slave.config[:work_dir]))
      end
    end
  end

  results = []
  threads.each do |t|
    begin
      results << t.value
    rescue Timeout::Error
      DeepTest.logger.error "Timeout syncing to #{t[:receiver].__drburi}"
      raise
    end
  end
  
  puts "Sync took #{Time.now - sync_start} seconds"
end

#spawn_worker_server(options) ⇒ Object



11
12
13
14
15
16
# File 'lib/deep_test/distributed/multi_test_server_proxy.rb', line 11

def spawn_worker_server(options)
  DeepTest.logger.debug "dispatch spawn_worker_server for #{options.origin_hostname}"
  WorkerServerProxy.new options,
                        @slave_controller.dispatch(:spawn_worker_server, 
                                                   options)
end

#sync(options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/deep_test/distributed/multi_test_server_proxy.rb', line 18

def sync(options)
  if options.sync_options[:push_code]
    multi_push_sync(options)
  else
    DeepTest.logger.debug "dispatch sync for #{options.origin_hostname}"
    @slave_controller.dispatch(:sync, options)
  end
end