Class: Sauce::Utilities::Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/sauce/utilities/connect.rb

Defined Under Namespace

Classes: TunnelNeverStarted

Constant Summary collapse

TIMEOUT =

Magic Numbers!

90

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.tunnelObject (readonly)

Returns the value of attribute tunnel.



61
62
63
# File 'lib/sauce/utilities/connect.rb', line 61

def tunnel
  @tunnel
end

Class Method Details

.closeObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sauce/utilities/connect.rb', line 48

def self.close
  if @tunnel
    if ParallelTests.first_process?
      Sauce.logger.debug "#{Thread.current.object_id} - First parallel process waiting for other processes before closing Sauce Connect."
      ParallelTests.wait_for_other_processes_to_finish
      Sauce.logger.debug "#{Thread.current.object_id} - All other parallel processes closed - Closing Sauce Connect tunnel #{@tunnel}."
      @tunnel.disconnect
      @tunnel = nil
    end
  end
end

.start(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sauce/utilities/connect.rb', line 13

def self.start(options={})
  begin
    Sauce.logger.debug "Requiring Sauce Connect gem."
    require "sauce/connect"
  rescue LoadError => e
    STDERR.puts 'Please install the `sauce-connect` gem if you intend on using Sauce Connect with your tests!'
    exit(1)
  end

  options[:timeout] = TIMEOUT unless options[:timeout]
  if ParallelTests.first_process?
    Sauce.logger.debug "#{Thread.current.object_id} - First parallel process attempting to start Sauce Connect."
    unless @tunnel
      @tunnel = Sauce::Connect.new options
      @tunnel.connect
      @tunnel.wait_until_ready
    else
      Sauce.logger.warn "#{Thread.current.object_id} - Tunnel already existed somehow."
    end
    @tunnel
  else
    Sauce.logger.debug "#{Thread.current.object_id} - Waiting for a Sauce Connect tunnel to be ready."
    timeout_after = Time.now + options[:timeout]
    # Ensure first process has a change to start up
    sleep 5
    readyfile_found = File.exist? "sauce_connect.ready" 
    until (Time.now > timeout_after) || readyfile_found
      readyfile_found = File.exist? "sauce_connect.ready"
      sleep 1
    end

    raise(TunnelNeverStarted, "Sauce Connect was not started within #{TIMEOUT} seconds") unless readyfile_found
  end
end

.start_from_config(config) ⇒ Object



9
10
11
# File 'lib/sauce/utilities/connect.rb', line 9

def self.start_from_config(config)
  self.start(:host => config[:application_host], :port => config[:application_port], :quiet => true)
end