bbq-spawn 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/bbq-spawn.gemspec +25 -0
- data/lib/bbq/spawn/version.rb +5 -0
- data/lib/bbq/spawn.rb +106 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a8f9fac05331610bc6102d7fa7d217da2eb4678
|
4
|
+
data.tar.gz: 5a064347a18bfff381c1bf3f54ee028b35ececc4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a5f758fe1dc8493ab42eef3cda068e329d2dcda26001b8b5873539c049d5ccbc8885626157617976c2800da371cd9372a7f647a39a10f671192ba467a9eecd7
|
7
|
+
data.tar.gz: be65348d806a6323a606005bf87c4f23fa11d37bb3be72b7134826b693febe57ac6641641edf424b356316c5eee213262ab7102d074536da600a614d71bcbe13
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Paweł Pacana
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bbq-spawn.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bbq/spawn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bbq-spawn"
|
8
|
+
spec.version = Bbq::Spawn::VERSION
|
9
|
+
spec.authors = ["Paweł Pacana"]
|
10
|
+
spec.email = ["pawel.pacana@gmail.com"]
|
11
|
+
spec.description = %q{Spawn and coordinate background processes for black box testing.}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "childprocess"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/bbq/spawn.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require "bbq/spawn/version"
|
2
|
+
require "childprocess"
|
3
|
+
require "forwardable"
|
4
|
+
require "socket"
|
5
|
+
require "timeout"
|
6
|
+
require "net/http"
|
7
|
+
|
8
|
+
module Bbq
|
9
|
+
module Spawn
|
10
|
+
class Executor
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :@process, :start, :stop, :io
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
@process = ChildProcess.build(*args)
|
17
|
+
yield @process if block_given?
|
18
|
+
@process
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class CoordinatedExecutor
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
def_delegators :@executor, :stop
|
26
|
+
|
27
|
+
def initialize(executor, options = {})
|
28
|
+
@executor = executor
|
29
|
+
@timeout = options.fetch(:timeout, 10)
|
30
|
+
@banner = options[:banner]
|
31
|
+
@host = options[:host]
|
32
|
+
@port = options[:port]
|
33
|
+
@url = options[:url]
|
34
|
+
|
35
|
+
@reader, @writer = IO.pipe
|
36
|
+
end
|
37
|
+
|
38
|
+
def start
|
39
|
+
@executor.io.stdout = @executor.io.stderr = @writer
|
40
|
+
@executor.start
|
41
|
+
@writer.close
|
42
|
+
end
|
43
|
+
|
44
|
+
def join
|
45
|
+
Timeout.timeout(@timeout) do
|
46
|
+
wait_for_io if @banner
|
47
|
+
wait_for_socket if @port and @host
|
48
|
+
wait_for_response if @url
|
49
|
+
end
|
50
|
+
rescue Timeout::Error
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def wait_for_io
|
55
|
+
loop do
|
56
|
+
case @reader.readpartial(8192)
|
57
|
+
when @banner then break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
rescue EOFError
|
61
|
+
end
|
62
|
+
|
63
|
+
def wait_for_socket
|
64
|
+
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
65
|
+
addr = Socket.pack_sockaddr_in(@port, @host)
|
66
|
+
|
67
|
+
socket.connect(addr)
|
68
|
+
rescue Errno::ECONNREFUSED
|
69
|
+
retry
|
70
|
+
ensure
|
71
|
+
socket.close
|
72
|
+
end
|
73
|
+
|
74
|
+
def wait_for_response
|
75
|
+
begin
|
76
|
+
Net::HTTP.start(@url) do |http|
|
77
|
+
http.open_timeout = 5
|
78
|
+
http.read_timeout = 5
|
79
|
+
http.head('/')
|
80
|
+
end
|
81
|
+
rescue SocketError
|
82
|
+
retry
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Orchestrator
|
88
|
+
def initialize
|
89
|
+
@executors = []
|
90
|
+
end
|
91
|
+
|
92
|
+
def coordinate(executor, options = {})
|
93
|
+
@executors << CoordinatedExecutor.new(executor, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def start
|
97
|
+
@executors.each(&:start)
|
98
|
+
@executors.each(&:join)
|
99
|
+
end
|
100
|
+
|
101
|
+
def stop
|
102
|
+
@executors.each(&:stop)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bbq-spawn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Pacana
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: childprocess
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Spawn and coordinate background processes for black box testing.
|
56
|
+
email:
|
57
|
+
- pawel.pacana@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bbq-spawn.gemspec
|
68
|
+
- lib/bbq/spawn.rb
|
69
|
+
- lib/bbq/spawn/version.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Spawn and coordinate background processes for black box testing.
|
94
|
+
test_files: []
|