Class: DeepTest::Distributed::Beachhead

Inherits:
LocalDeployment show all
Includes:
DeepTest::Demon
Defined in:
lib/deep_test/distributed/beachhead.rb

Defined Under Namespace

Classes: LoadFiles

Constant Summary collapse

MERCY_KILLING_GRACE_PERIOD =
10 * 60
DeployAgents =
"DeployAgents"
Done =
"Done"

Instance Attribute Summary

Attributes inherited from LocalDeployment

#warlock

Instance Method Summary collapse

Methods inherited from LocalDeployment

#number_of_agents

Constructor Details

#initialize(base_path, options) ⇒ Beachhead

Returns a new instance of Beachhead.



8
9
10
11
# File 'lib/deep_test/distributed/beachhead.rb', line 8

def initialize(base_path, options)
  super options
  @base_path = base_path
end

Instance Method Details

#agents_deployed?Boolean

Returns:

  • (Boolean)


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

def agents_deployed?
  @agents_deployed
end

#daemonize(grace_period = MERCY_KILLING_GRACE_PERIOD) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/deep_test/distributed/beachhead.rb', line 81

def daemonize(grace_period = MERCY_KILLING_GRACE_PERIOD)
  innie, outie = IO.pipe

  warlock.start "Beachhead", self, innie, outie, grace_period

  outie.close
  port = innie.gets
  innie.close
  port.to_i
end

#deploy_agentsObject



35
36
37
38
39
# File 'lib/deep_test/distributed/beachhead.rb', line 35

def deploy_agents
  @agents_deployed = true
  super
  warlock.exit_when_none_running
end

#execute(innie, outie, grace_period) ⇒ Object



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

def execute(innie, outie, grace_period)
  innie.close

  switchboard = Telegraph::Switchboard.new
  operator = Telegraph::Operator.listen "0.0.0.0", 0, switchboard

  DeepTest.logger.debug { "Beachhead started on port #{operator.port}" }

  outie.write operator.port
  outie.close

  launch_mercy_killer grace_period

  loop do
    begin
      switchboard.process_messages :timeout => 1 do |message, wire|
        case message.body
        when LoadFiles
          load_files message.body.files
        when DeployAgents
          deploy_agents
          wire.send_message Done
          operator.shutdown
          break
        end
      end
    end
  end
end

#forked(*args) ⇒ Object



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

def forked(*args)
  $stdout.reopen("/dev/null")
  $stderr.reopen("/dev/null")
  super
end

#launch_mercy_killer(grace_period) ⇒ Object



13
14
15
16
17
18
# File 'lib/deep_test/distributed/beachhead.rb', line 13

def launch_mercy_killer(grace_period)
  Thread.new do
    sleep grace_period
    exit(0) unless agents_deployed?
  end
end

#load_files(files) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/deep_test/distributed/beachhead.rb', line 20

def load_files(files)
  spec_support_path = File.expand_path(File.dirname(__FILE__) + "/../spec") 
  Dir.chdir @base_path
  resolver = FilenameResolver.new(@base_path)
  files.each do |file|
    load resolver.resolve(file)
  end

  # Load rspec support if rspec is available now that we've loaded the host project files
  #
  DeepTest::RSpecDetector.if_rspec_available do
    require spec_support_path
  end
end