pipemaster 0.3.1
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.
- data/CHANGELOG +0 -0
- data/Gemfile +5 -0
- data/LICENSE +55 -0
- data/README.rdoc +61 -0
- data/Rakefile +51 -0
- data/bin/pipemaster +100 -0
- data/lib/pipemaster.rb +8 -0
- data/lib/pipemaster/client.rb +121 -0
- data/lib/pipemaster/configurator.rb +228 -0
- data/lib/pipemaster/server.rb +164 -0
- data/lib/pipemaster/worker.rb +4 -0
- data/pipemaster.gemspec +18 -0
- data/test/test_helper.rb +268 -0
- data/test/unit/test_configurator.rb +151 -0
- data/test/unit/test_server.rb +84 -0
- metadata +84 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
|
3
|
+
require 'test/test_helper'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'pipemaster'
|
6
|
+
|
7
|
+
TestStruct = Struct.new(
|
8
|
+
*(Pipemaster::Configurator::DEFAULTS.keys + %w(listener_opts listeners)))
|
9
|
+
class TestConfigurator < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_config_init
|
12
|
+
assert_nothing_raised { Pipemaster::Configurator.new {} }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_expand_addr
|
16
|
+
meth = Pipemaster::Configurator.new.method(:expand_addr)
|
17
|
+
|
18
|
+
assert_equal "/var/run/pipemaster.sock", meth.call("/var/run/pipemaster.sock")
|
19
|
+
assert_equal "#{Dir.pwd}/foo/bar.sock", meth.call("unix:foo/bar.sock")
|
20
|
+
|
21
|
+
path = meth.call("~/foo/bar.sock")
|
22
|
+
assert_equal "/", path[0..0]
|
23
|
+
assert_match %r{/foo/bar\.sock\z}, path
|
24
|
+
|
25
|
+
path = meth.call("~root/foo/bar.sock")
|
26
|
+
assert_equal "/", path[0..0]
|
27
|
+
assert_match %r{/foo/bar\.sock\z}, path
|
28
|
+
|
29
|
+
assert_equal "1.2.3.4:2007", meth.call('1.2.3.4:2007')
|
30
|
+
assert_equal "0.0.0.0:2007", meth.call('0.0.0.0:2007')
|
31
|
+
assert_equal "0.0.0.0:2007", meth.call(':2007')
|
32
|
+
assert_equal "0.0.0.0:2007", meth.call('*:2007')
|
33
|
+
assert_equal "0.0.0.0:2007", meth.call('2007')
|
34
|
+
assert_equal "0.0.0.0:2007", meth.call(2007)
|
35
|
+
|
36
|
+
# the next two aren't portable, consider them unsupported for now
|
37
|
+
# assert_match %r{\A\d+\.\d+\.\d+\.\d+:2007\z}, meth.call('1:2007')
|
38
|
+
# assert_match %r{\A\d+\.\d+\.\d+\.\d+:2007\z}, meth.call('2:2007')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_config_invalid
|
42
|
+
tmp = Tempfile.new('Pipefile')
|
43
|
+
tmp.syswrite(%q(asdfasdf "hello-world"))
|
44
|
+
assert_raises(NoMethodError) do
|
45
|
+
Pipemaster::Configurator.new(:config_file => tmp.path)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_config_non_existent
|
50
|
+
tmp = Tempfile.new('Pipefile')
|
51
|
+
path = tmp.path
|
52
|
+
tmp.close!
|
53
|
+
assert_raises(Errno::ENOENT) do
|
54
|
+
Pipemaster::Configurator.new(:config_file => path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_config_defaults
|
59
|
+
cfg = Pipemaster::Configurator.new(:use_defaults => true)
|
60
|
+
test_struct = TestStruct.new
|
61
|
+
assert_nothing_raised { cfg.commit!(test_struct) }
|
62
|
+
Pipemaster::Configurator::DEFAULTS.each do |key,value|
|
63
|
+
assert_equal value, test_struct.__send__(key)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_config_defaults_skip
|
68
|
+
cfg = Pipemaster::Configurator.new(:use_defaults => true)
|
69
|
+
skip = [ :logger ]
|
70
|
+
test_struct = TestStruct.new
|
71
|
+
assert_nothing_raised { cfg.commit!(test_struct, :skip => skip) }
|
72
|
+
Pipemaster::Configurator::DEFAULTS.each do |key,value|
|
73
|
+
next if skip.include?(key)
|
74
|
+
assert_equal value, test_struct.__send__(key)
|
75
|
+
end
|
76
|
+
assert_nil test_struct.logger
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_listen_options
|
80
|
+
tmp = Tempfile.new('Pipefile')
|
81
|
+
expect = { :sndbuf => 1, :rcvbuf => 2, :backlog => 10 }.freeze
|
82
|
+
listener = "127.0.0.1:12345"
|
83
|
+
tmp.syswrite("listen '#{listener}', #{expect.inspect}\n")
|
84
|
+
cfg = nil
|
85
|
+
assert_nothing_raised do
|
86
|
+
cfg = Pipemaster::Configurator.new(:config_file => tmp.path)
|
87
|
+
end
|
88
|
+
test_struct = TestStruct.new
|
89
|
+
assert_nothing_raised { cfg.commit!(test_struct) }
|
90
|
+
assert(listener_opts = test_struct.listener_opts)
|
91
|
+
assert_equal expect, listener_opts[listener]
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_listen_option_bad
|
95
|
+
tmp = Tempfile.new('Pipefile')
|
96
|
+
expect = { :sndbuf => "five" }
|
97
|
+
listener = "127.0.0.1:12345"
|
98
|
+
tmp.syswrite("listen '#{listener}', #{expect.inspect}\n")
|
99
|
+
assert_raises(ArgumentError) do
|
100
|
+
Pipemaster::Configurator.new(:config_file => tmp.path)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_listen_option_bad_delay
|
105
|
+
tmp = Tempfile.new('Pipefile')
|
106
|
+
expect = { :delay => "five" }
|
107
|
+
listener = "127.0.0.1:12345"
|
108
|
+
tmp.syswrite("listen '#{listener}', #{expect.inspect}\n")
|
109
|
+
assert_raises(ArgumentError) do
|
110
|
+
Pipemaster::Configurator.new(:config_file => tmp.path)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_listen_option_float_delay
|
115
|
+
tmp = Tempfile.new('Pipefile')
|
116
|
+
expect = { :delay => 0.5 }
|
117
|
+
listener = "127.0.0.1:12345"
|
118
|
+
tmp.syswrite("listen '#{listener}', #{expect.inspect}\n")
|
119
|
+
assert_nothing_raised do
|
120
|
+
Pipemaster::Configurator.new(:config_file => tmp.path)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_listen_option_int_delay
|
125
|
+
tmp = Tempfile.new('Pipefile')
|
126
|
+
expect = { :delay => 5 }
|
127
|
+
listener = "127.0.0.1:12345"
|
128
|
+
tmp.syswrite("listen '#{listener}', #{expect.inspect}\n")
|
129
|
+
assert_nothing_raised do
|
130
|
+
Pipemaster::Configurator.new(:config_file => tmp.path)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_after_fork_proc
|
135
|
+
test_struct = TestStruct.new
|
136
|
+
[ proc { |a,b| }, Proc.new { |a,b| }, lambda { |a,b| } ].each do |my_proc|
|
137
|
+
Pipemaster::Configurator.new(:after_fork => my_proc).commit!(test_struct)
|
138
|
+
assert_equal my_proc, test_struct.after_fork
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_after_fork_wrong_arity
|
143
|
+
[ proc { |a| }, Proc.new { }, lambda { |a,b,c| } ].each do |my_proc|
|
144
|
+
assert_raises(ArgumentError) do
|
145
|
+
Pipemaster::Configurator.new(:after_fork => my_proc)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
|
3
|
+
# Copyright (c) 2005 Zed A. Shaw
|
4
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
5
|
+
#
|
6
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
7
|
+
# for more information.
|
8
|
+
|
9
|
+
require 'test/test_helper'
|
10
|
+
|
11
|
+
class ServerTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@port = unused_port
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
if @server
|
19
|
+
redirect_test_io do
|
20
|
+
wait_master_ready("test_stderr.#$$.log")
|
21
|
+
File.truncate("test_stderr.#$$.log", 0)
|
22
|
+
Process.kill 9, @pid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def start(options = nil)
|
28
|
+
redirect_test_io do
|
29
|
+
@server = Pipemaster::Server.new({:listeners => [ "127.0.0.1:#{@port}" ]}.merge(options || {}))
|
30
|
+
@pid = fork { @server.start }
|
31
|
+
at_exit { Process.kill @pid, 9 }
|
32
|
+
wait_master_ready("test_stderr.#$$.log")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_master_and_fork
|
37
|
+
start :commands => { :ppid => lambda { puts Process.ppid } }
|
38
|
+
results = hit("127.0.0.1:#@port", "ppid")
|
39
|
+
assert_equal @pid, results.last.to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_broken_pipefile
|
43
|
+
tmp = Tempfile.new('Pipefile')
|
44
|
+
ObjectSpace.undefine_finalizer(tmp)
|
45
|
+
tmp.write "raise RuntimeError"
|
46
|
+
tmp.flush
|
47
|
+
teardown
|
48
|
+
assert_raises RuntimeError do
|
49
|
+
start :config_file=>tmp.path
|
50
|
+
end
|
51
|
+
ensure
|
52
|
+
tmp.close!
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_no_command
|
56
|
+
start
|
57
|
+
results = hit("127.0.0.1:#@port", "test")
|
58
|
+
assert_equal 1, results.first
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_arguments
|
62
|
+
start :commands => { :args => lambda { |x,y| $stdout << "#{x} - #{y}" } }
|
63
|
+
results = hit("127.0.0.1:#@port", "args", "foo", "bar")
|
64
|
+
assert_equal "foo - bar", results.last
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_streams
|
68
|
+
start :commands => { :reverse => lambda { $stdout << $stdin.read.reverse } }
|
69
|
+
client = Pipemaster::Client.new("127.0.0.1:#@port")
|
70
|
+
tmp = Tempfile.new('input')
|
71
|
+
ObjectSpace.undefine_finalizer(tmp)
|
72
|
+
tmp.write "foo bar"
|
73
|
+
tmp.flush
|
74
|
+
tmp.rewind
|
75
|
+
client.input = tmp
|
76
|
+
output = StringIO.new
|
77
|
+
client.output = output
|
78
|
+
client.request :reverse
|
79
|
+
assert_equal "rab oof", client.output.string
|
80
|
+
ensure
|
81
|
+
tmp.close!
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pipemaster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Assaf Arkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: unicorn
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.96"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: assaf@labnotes.org
|
27
|
+
executables:
|
28
|
+
- pipemaster
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- CHANGELOG
|
34
|
+
files:
|
35
|
+
- bin/pipemaster
|
36
|
+
- lib/pipemaster/client.rb
|
37
|
+
- lib/pipemaster/configurator.rb
|
38
|
+
- lib/pipemaster/server.rb
|
39
|
+
- lib/pipemaster/worker.rb
|
40
|
+
- lib/pipemaster.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
- test/unit/test_configurator.rb
|
43
|
+
- test/unit/test_server.rb
|
44
|
+
- CHANGELOG
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- Gemfile
|
49
|
+
- pipemaster.gemspec
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://labnotes.org
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message: To get started run pipemaster --help
|
55
|
+
rdoc_options:
|
56
|
+
- --title
|
57
|
+
- Pipemaster 0.3.1
|
58
|
+
- --main
|
59
|
+
- README.rdoc
|
60
|
+
- --webcvs
|
61
|
+
- http://github.com/assaf/pipemaster
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Use the fork
|
83
|
+
test_files: []
|
84
|
+
|