Class: SauceTunnel::Tunnel
- Inherits:
-
Object
- Object
- SauceTunnel::Tunnel
- Defined in:
- lib/sauce_tunnel/tunnel.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#sc_args ⇒ Object
readonly
Returns the value of attribute sc_args.
-
#sc_path ⇒ Object
readonly
Returns the value of attribute sc_path.
Instance Method Summary collapse
- #await ⇒ Object
- #connect ⇒ Object
-
#initialize(sc_path: "sc", sc_args: [], quiet: false, timeout: 120, shutdown_timeout: 20) ⇒ Tunnel
constructor
A new instance of Tunnel.
- #quiet? ⇒ Boolean
- #terminate ⇒ Object
Constructor Details
#initialize(sc_path: "sc", sc_args: [], quiet: false, timeout: 120, shutdown_timeout: 20) ⇒ Tunnel
Returns a new instance of Tunnel.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sauce_tunnel/tunnel.rb', line 7 def initialize(sc_path: "sc", sc_args: [], quiet: false, timeout: 120, shutdown_timeout: 20) @sc_path = sc_path @sc_args = sc_args @quiet = quiet @timeout = timeout @shutdown_timeout = shutdown_timeout @queue = SauceTunnel::SimpleQueue.new @up = false end |
Instance Attribute Details
#sc_args ⇒ Object (readonly)
Returns the value of attribute sc_args.
5 6 7 |
# File 'lib/sauce_tunnel/tunnel.rb', line 5 def sc_args @sc_args end |
#sc_path ⇒ Object (readonly)
Returns the value of attribute sc_path.
5 6 7 |
# File 'lib/sauce_tunnel/tunnel.rb', line 5 def sc_path @sc_path end |
Instance Method Details
#await ⇒ Object
31 32 33 34 35 36 |
# File 'lib/sauce_tunnel/tunnel.rb', line 31 def await @up ||= @queue.pop(@timeout) self rescue ThreadError raise ConnectionError, "timed out trying to establish connection to SauceLabs" end |
#connect ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sauce_tunnel/tunnel.rb', line 18 def connect return if @wait_thread # don't start twice @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(Shellwords.join([sc_path] + [sc_args].flatten)) @read_thread = Thread.new do while line = @stdout.gets puts line unless quiet? @queue.push(true) if line =~ /sauce connect is up/i end end end |
#quiet? ⇒ Boolean
47 48 49 |
# File 'lib/sauce_tunnel/tunnel.rb', line 47 def quiet? @quiet end |
#terminate ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/sauce_tunnel/tunnel.rb', line 38 def terminate if @wait_thread Process.kill("TERM", @wait_thread.pid) @wait_thread.join(@shutdown_timeout) end rescue Errno::ESRCH # do nothing, tunnel already shut down end |