mongrel2 0.38.0 → 0.39.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +6 -0
- data/Manifest.txt +5 -3
- data/Rakefile +2 -2
- data/data/mongrel2/config.sql +6 -1
- data/lib/mongrel2.rb +5 -2
- data/lib/mongrel2/config.rb +1 -0
- data/lib/mongrel2/config/server.rb +15 -0
- data/lib/mongrel2/config/xrequest.rb +45 -0
- data/lib/mongrel2/connection.rb +4 -5
- data/lib/mongrel2/control.rb +2 -2
- data/lib/mongrel2/handler.rb +1 -1
- data/spec/{lib/constants.rb → constants.rb} +0 -2
- data/spec/{lib/helpers.rb → helpers.rb} +9 -12
- data/spec/{lib/matchers.rb → matchers.rb} +2 -12
- data/spec/mongrel2/config/directory_spec.rb +16 -27
- data/spec/mongrel2/config/dsl_spec.rb +115 -98
- data/spec/mongrel2/config/filter_spec.rb +1 -12
- data/spec/mongrel2/config/handler_spec.rb +23 -33
- data/spec/mongrel2/config/host_spec.rb +1 -12
- data/spec/mongrel2/config/log_spec.rb +13 -24
- data/spec/mongrel2/config/proxy_spec.rb +1 -12
- data/spec/mongrel2/config/route_spec.rb +5 -15
- data/spec/mongrel2/config/server_spec.rb +23 -34
- data/spec/mongrel2/config/setting_spec.rb +1 -12
- data/spec/mongrel2/config/statistic_spec.rb +1 -12
- data/spec/mongrel2/config/xrequest_spec.rb +19 -0
- data/spec/mongrel2/config_spec.rb +17 -29
- data/spec/mongrel2/connection_spec.rb +41 -53
- data/spec/mongrel2/constants_spec.rb +2 -14
- data/spec/mongrel2/control_spec.rb +44 -56
- data/spec/mongrel2/handler_spec.rb +64 -76
- data/spec/mongrel2/httprequest_spec.rb +21 -31
- data/spec/mongrel2/httpresponse_spec.rb +55 -67
- data/spec/mongrel2/request_spec.rb +53 -62
- data/spec/mongrel2/response_spec.rb +15 -24
- data/spec/mongrel2/table_spec.rb +41 -53
- data/spec/mongrel2/websocket_spec.rb +95 -104
- data/spec/mongrel2_spec.rb +3 -12
- metadata +13 -11
- metadata.gz.sig +0 -0
@@ -1,19 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
3
|
+
require_relative '../../helpers'
|
12
4
|
|
13
5
|
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
16
|
-
|
17
6
|
require 'mongrel2'
|
18
7
|
require 'mongrel2/config'
|
19
8
|
|
@@ -1,19 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
3
|
+
require_relative '../../helpers'
|
12
4
|
|
13
5
|
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
16
|
-
|
17
6
|
require 'mongrel2'
|
18
7
|
require 'mongrel2/config'
|
19
8
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../../helpers'
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'mongrel2'
|
7
|
+
require 'mongrel2/config'
|
8
|
+
|
9
|
+
|
10
|
+
#####################################################################
|
11
|
+
### C O N T E X T S
|
12
|
+
#####################################################################
|
13
|
+
|
14
|
+
describe Mongrel2::Config::XRequest do
|
15
|
+
|
16
|
+
# No functionality outside of Sequel::Model's purview yet
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
12
|
-
|
13
|
-
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
3
|
+
require_relative '../helpers'
|
16
4
|
|
17
5
|
require 'mongrel2'
|
18
6
|
require 'mongrel2/config'
|
@@ -25,7 +13,7 @@ require 'mongrel2/config'
|
|
25
13
|
describe Mongrel2::Config do
|
26
14
|
|
27
15
|
before( :all ) do
|
28
|
-
setup_logging(
|
16
|
+
setup_logging()
|
29
17
|
setup_config_db()
|
30
18
|
end
|
31
19
|
|
@@ -38,8 +26,8 @@ describe Mongrel2::Config do
|
|
38
26
|
it "has a factory method for creating derivative classes" do
|
39
27
|
begin
|
40
28
|
model_class = Mongrel2::Config( :hookers )
|
41
|
-
model_class.
|
42
|
-
model_class.dataset.first_source.
|
29
|
+
expect( model_class ).to satisfy {|klass| klass < Mongrel2::Config }
|
30
|
+
expect( model_class.dataset.first_source ).to eq( :hookers )
|
43
31
|
ensure
|
44
32
|
# Remove the example class from the list of subclasses so it
|
45
33
|
# doesn't affect later tests
|
@@ -50,7 +38,7 @@ describe Mongrel2::Config do
|
|
50
38
|
it "can reset the database handle for the config classes" do
|
51
39
|
db = Mongrel2::Config.in_memory_db
|
52
40
|
Mongrel2::Config.db = db
|
53
|
-
Mongrel2::Config::Directory.db.
|
41
|
+
expect( Mongrel2::Config::Directory.db ).to equal( db )
|
54
42
|
end
|
55
43
|
|
56
44
|
it "has a convenience method for fetching an Array of all of its configured servers" do
|
@@ -65,47 +53,47 @@ describe Mongrel2::Config do
|
|
65
53
|
default_host: 'localhost',
|
66
54
|
port: 8275
|
67
55
|
)
|
68
|
-
Mongrel2::Config.servers.
|
69
|
-
Mongrel2::Config.servers.first.uuid.
|
56
|
+
expect( Mongrel2::Config.servers ).to have( 1 ).member
|
57
|
+
expect( Mongrel2::Config.servers.first.uuid ).to eq( TEST_UUID )
|
70
58
|
end
|
71
59
|
|
72
60
|
it "has a convenience method for getting a setting's value" do
|
73
61
|
Mongrel2::Config.init_database
|
74
62
|
Mongrel2::Config::Setting.dataset.truncate
|
75
63
|
Mongrel2::Config::Setting.create( key: 'control_port', value: 'ipc://var/run/control.sock' )
|
76
|
-
Mongrel2::Config.settings.
|
77
|
-
Mongrel2::Config.settings.
|
78
|
-
Mongrel2::Config.settings[ :control_port ].
|
64
|
+
expect( Mongrel2::Config.settings ).to respond_to( :[] )
|
65
|
+
expect( Mongrel2::Config.settings ).to have( 1 ).member
|
66
|
+
expect( Mongrel2::Config.settings[ :control_port ] ).to eq( 'ipc://var/run/control.sock' )
|
79
67
|
end
|
80
68
|
|
81
69
|
it "can read the configuration schema from a data file" do
|
82
|
-
Mongrel2::Config.load_config_schema.
|
70
|
+
expect( Mongrel2::Config.load_config_schema ).to match( /create table server/i )
|
83
71
|
end
|
84
72
|
|
85
73
|
it "knows whether or not its database has been initialized" do
|
86
74
|
Mongrel2::Config.db = Mongrel2::Config.in_memory_db
|
87
|
-
Mongrel2::Config.database_initialized
|
75
|
+
expect( Mongrel2::Config.database_initialized? ).to be_false()
|
88
76
|
Mongrel2::Config.init_database!
|
89
|
-
Mongrel2::Config.database_initialized
|
77
|
+
expect( Mongrel2::Config.database_initialized? ).to be_true()
|
90
78
|
end
|
91
79
|
|
92
80
|
it "doesn't re-initialize the database if the non-bang version of init_database is used" do
|
93
81
|
Mongrel2::Config.db = Mongrel2::Config.in_memory_db
|
94
82
|
Mongrel2::Config.init_database
|
95
83
|
|
96
|
-
Mongrel2::Config.
|
84
|
+
expect( Mongrel2::Config ).to_not receive( :load_config_schema )
|
97
85
|
Mongrel2::Config.init_database
|
98
86
|
end
|
99
87
|
|
100
88
|
it "can return the path to the config DB as a Pathname if it's pointing at a file" do
|
101
89
|
Mongrel2::Config.db = Sequel.
|
102
90
|
connect( adapter: Mongrel2::Config.sqlite_adapter, database: 'config-spec.sqlite' )
|
103
|
-
Mongrel2::Config.dbname.
|
91
|
+
expect( Mongrel2::Config.dbname ).to eq( 'config-spec.sqlite' )
|
104
92
|
end
|
105
93
|
|
106
94
|
it "returns nil if asked for the pathname to an in-memory database" do
|
107
95
|
Mongrel2::Config.db = Mongrel2::Config.in_memory_db
|
108
|
-
Mongrel2::Config.dbname.
|
96
|
+
expect( Mongrel2::Config.dbname ).to be_nil()
|
109
97
|
end
|
110
98
|
|
111
99
|
describe "Configurability support", :if => defined?( Configurability ) do
|
@@ -114,7 +102,7 @@ describe Mongrel2::Config do
|
|
114
102
|
it_should_behave_like "an object with Configurability"
|
115
103
|
|
116
104
|
it "uses the 'mongrel2' config section" do
|
117
|
-
Mongrel2::Config.config_key.
|
105
|
+
expect( Mongrel2::Config.config_key ).to eq( :mongrel2 )
|
118
106
|
end
|
119
107
|
|
120
108
|
end
|
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
12
|
-
|
13
|
-
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
3
|
+
require_relative '../helpers'
|
16
4
|
|
17
5
|
require 'mongrel2'
|
18
6
|
require 'mongrel2/connection'
|
@@ -26,7 +14,7 @@ describe Mongrel2::Connection do
|
|
26
14
|
include Mongrel2::Config::DSL
|
27
15
|
|
28
16
|
before( :all ) do
|
29
|
-
setup_logging(
|
17
|
+
setup_logging()
|
30
18
|
end
|
31
19
|
|
32
20
|
# Ensure 0MQ never actually gets called
|
@@ -47,54 +35,54 @@ describe Mongrel2::Connection do
|
|
47
35
|
|
48
36
|
|
49
37
|
it "doesn't connect to the endpoints when it's created" do
|
50
|
-
@conn.instance_variable_get( :@request_sock ).
|
51
|
-
@conn.instance_variable_get( :@response_sock ).
|
38
|
+
expect( @conn.instance_variable_get( :@request_sock ) ).to be_nil()
|
39
|
+
expect( @conn.instance_variable_get( :@response_sock ) ).to be_nil()
|
52
40
|
end
|
53
41
|
|
54
42
|
it "connects to the endpoints specified on demand" do
|
55
43
|
request_sock = double( "request socket" )
|
56
44
|
response_sock = double( "response socket" )
|
57
45
|
|
58
|
-
@ctx.
|
59
|
-
request_sock.
|
60
|
-
request_sock.
|
46
|
+
expect( @ctx ).to receive( :socket ).with( :PULL ).and_return( request_sock )
|
47
|
+
expect( request_sock ).to receive( :linger= ).with( 0 )
|
48
|
+
expect( request_sock ).to receive( :connect ).with( TEST_SEND_SPEC )
|
61
49
|
|
62
|
-
@ctx.
|
63
|
-
response_sock.
|
64
|
-
|
65
|
-
response_sock.
|
50
|
+
expect( @ctx ).to receive( :socket ).with( :PUB ).and_return( response_sock )
|
51
|
+
expect( response_sock ).to receive( :linger= ).with( 0 )
|
52
|
+
expect( response_sock ).to_not receive( :identity= )
|
53
|
+
expect( response_sock ).to receive( :connect ).with( TEST_RECV_SPEC )
|
66
54
|
|
67
|
-
@conn.request_sock.
|
68
|
-
@conn.response_sock.
|
55
|
+
expect( @conn.request_sock ).to eq( request_sock )
|
56
|
+
expect( @conn.response_sock ).to eq( response_sock )
|
69
57
|
end
|
70
58
|
|
71
59
|
it "stringifies as a description of the appid and both sockets" do
|
72
|
-
@conn.to_s.
|
60
|
+
expect( @conn.to_s ).to eq( "{#{TEST_UUID}} #{TEST_SEND_SPEC} <-> #{TEST_RECV_SPEC}" )
|
73
61
|
end
|
74
62
|
|
75
63
|
context "after a connection has been established" do
|
76
64
|
|
77
65
|
before( :each ) do
|
78
|
-
@request_sock = double( "request socket", :
|
79
|
-
@response_sock = double( "response socket", :
|
66
|
+
@request_sock = double( "request socket", :linger= => nil, :connect => nil )
|
67
|
+
@response_sock = double( "response socket", :linger= => nil, :connect => nil )
|
80
68
|
|
81
|
-
@ctx.
|
82
|
-
@ctx.
|
69
|
+
allow( @ctx ).to receive( :socket ).with( :PULL ).and_return( @request_sock )
|
70
|
+
allow( @ctx ).to receive( :socket ).with( :PUB ).and_return( @response_sock )
|
83
71
|
|
84
72
|
@conn.connect
|
85
73
|
end
|
86
74
|
|
87
75
|
|
88
76
|
it "closes both of its sockets when closed" do
|
89
|
-
@request_sock.
|
90
|
-
@response_sock.
|
77
|
+
expect( @request_sock ).to receive( :close )
|
78
|
+
expect( @response_sock ).to receive( :close )
|
91
79
|
|
92
80
|
@conn.close
|
93
81
|
end
|
94
82
|
|
95
83
|
it "raises an exception if asked to fetch data after being closed" do
|
96
|
-
@request_sock.
|
97
|
-
@response_sock.
|
84
|
+
allow( @request_sock ).to receive( :close )
|
85
|
+
allow( @response_sock ).to receive( :close )
|
98
86
|
|
99
87
|
@conn.close
|
100
88
|
|
@@ -104,69 +92,69 @@ describe Mongrel2::Connection do
|
|
104
92
|
end
|
105
93
|
|
106
94
|
it "doesn't keep its request and response sockets when duped" do
|
107
|
-
request_sock2 = double( "request socket", :
|
108
|
-
response_sock2 = double( "response socket", :
|
109
|
-
@ctx.
|
110
|
-
@ctx.
|
95
|
+
request_sock2 = double( "request socket", :linger= => nil, :connect => nil )
|
96
|
+
response_sock2 = double( "response socket", :linger= => nil, :connect => nil )
|
97
|
+
allow( @ctx ).to receive( :socket ).with( :PULL ).and_return( request_sock2 )
|
98
|
+
allow( @ctx ).to receive( :socket ).with( :PUB ).and_return( response_sock2 )
|
111
99
|
|
112
100
|
duplicate = @conn.dup
|
113
101
|
|
114
|
-
duplicate.request_sock.
|
115
|
-
duplicate.response_sock.
|
102
|
+
expect( duplicate.request_sock ).to eq( request_sock2 )
|
103
|
+
expect( duplicate.response_sock ).to eq( response_sock2 )
|
116
104
|
end
|
117
105
|
|
118
106
|
it "doesn't keep its closed state when duped" do
|
119
|
-
@request_sock.
|
120
|
-
@response_sock.
|
107
|
+
expect( @request_sock ).to receive( :close )
|
108
|
+
expect( @response_sock ).to receive( :close )
|
121
109
|
|
122
110
|
@conn.close
|
123
111
|
|
124
112
|
duplicate = @conn.dup
|
125
|
-
duplicate.
|
113
|
+
expect( duplicate ).to_not be_closed()
|
126
114
|
end
|
127
115
|
|
128
116
|
it "can read raw request messages off of the request_sock" do
|
129
|
-
@request_sock.
|
130
|
-
@conn.recv.
|
117
|
+
expect( @request_sock ).to receive( :recv ).and_return( "the data" )
|
118
|
+
expect( @conn.recv ).to eq( "the data" )
|
131
119
|
end
|
132
120
|
|
133
121
|
it "can read request messages off of the request_sock as Mongrel2::Request objects" do
|
134
122
|
msg = make_request()
|
135
|
-
@request_sock.
|
136
|
-
@conn.receive.
|
123
|
+
expect( @request_sock ).to receive( :recv ).and_return( msg )
|
124
|
+
expect( @conn.receive ).to be_a( Mongrel2::Request )
|
137
125
|
end
|
138
126
|
|
139
127
|
it "can write raw response messages with a TNetString header onto the response_sock" do
|
140
|
-
@response_sock.
|
128
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 1:8, the data" )
|
141
129
|
@conn.send( TEST_UUID, 8, "the data" )
|
142
130
|
end
|
143
131
|
|
144
132
|
it "can write Mongrel2::Responses to the response_sock" do
|
145
|
-
@response_sock.
|
133
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 1:8, the data" )
|
146
134
|
|
147
135
|
response = Mongrel2::Response.new( TEST_UUID, 8, 'the data' )
|
148
136
|
@conn.reply( response )
|
149
137
|
end
|
150
138
|
|
151
139
|
it "can write raw response messages to more than one conn_id at the same time" do
|
152
|
-
@response_sock.
|
140
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 15:8 16 44 45 1833, the data" )
|
153
141
|
@conn.broadcast( TEST_UUID, [8, 16, 44, 45, 1833], 'the data' )
|
154
142
|
end
|
155
143
|
|
156
144
|
it "can write raw response messages to more than one conn_id at the same time" do
|
157
|
-
@response_sock.
|
145
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 15:8 16 44 45 1833, the data" )
|
158
146
|
@conn.broadcast( TEST_UUID, [8, 16, 44, 45, 1833], 'the data' )
|
159
147
|
end
|
160
148
|
|
161
149
|
it "can tell the connection a request or a response was from to close" do
|
162
|
-
@response_sock.
|
150
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 1:8, " )
|
163
151
|
|
164
152
|
response = Mongrel2::Response.new( TEST_UUID, 8 )
|
165
153
|
@conn.reply_close( response )
|
166
154
|
end
|
167
155
|
|
168
156
|
it "can broadcast a close to multiple connection IDs" do
|
169
|
-
@response_sock.
|
157
|
+
expect( @response_sock ).to receive( :send ).with( "#{TEST_UUID} 15:8 16 44 45 1833, " )
|
170
158
|
@conn.broadcast_close( TEST_UUID, [8, 16, 44, 45, 1833] )
|
171
159
|
end
|
172
160
|
|
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
12
|
-
|
13
|
-
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
3
|
+
require_relative '../helpers'
|
16
4
|
|
17
5
|
require 'mongrel2'
|
18
6
|
require 'mongrel2/connection'
|
@@ -25,7 +13,7 @@ require 'mongrel2/connection'
|
|
25
13
|
describe Mongrel2::Constants do
|
26
14
|
|
27
15
|
it "defines a default configuration URI" do
|
28
|
-
Mongrel2::Constants.constants.map( &:to_sym ).
|
16
|
+
expect( Mongrel2::Constants.constants.map( &:to_sym ) ).to include( :DEFAULT_CONFIG_URI )
|
29
17
|
end
|
30
18
|
|
31
19
|
end
|
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
12
|
-
|
13
|
-
require 'rspec'
|
14
|
-
|
15
|
-
require 'spec/lib/helpers'
|
3
|
+
require_relative '../helpers'
|
16
4
|
|
17
5
|
require 'mongrel2'
|
18
6
|
require 'mongrel2/control'
|
@@ -25,17 +13,17 @@ require 'mongrel2/control'
|
|
25
13
|
describe Mongrel2::Control do
|
26
14
|
|
27
15
|
before( :all ) do
|
28
|
-
setup_logging(
|
16
|
+
setup_logging()
|
29
17
|
end
|
30
18
|
|
31
19
|
before( :each ) do
|
32
20
|
@ctx = double( "ZMQ::Context" )
|
33
|
-
@socket = double( "ZMQ REQ socket", :connect => nil, :
|
34
|
-
@ctx.
|
21
|
+
@socket = double( "ZMQ REQ socket", :connect => nil, :linger= => nil )
|
22
|
+
allow( @ctx ).to receive( :socket ).with( :REQ ).and_return( @socket )
|
35
23
|
|
36
24
|
Mongrel2.instance_variable_set( :@zmq_ctx, @ctx )
|
37
25
|
|
38
|
-
FileTest.
|
26
|
+
allow( FileTest ).to receive( :socket? ).with( 'var/run/control' ). and_return( true )
|
39
27
|
|
40
28
|
@control = Mongrel2::Control.new( 'ipc://var/run/control' )
|
41
29
|
end
|
@@ -47,29 +35,29 @@ describe Mongrel2::Control do
|
|
47
35
|
|
48
36
|
|
49
37
|
it "sends a 'stop' command to the control port when #stop is called" do
|
50
|
-
@socket.
|
51
|
-
@socket.
|
38
|
+
expect( @socket ).to receive( :send ).with( "10:4:stop,0:}]" )
|
39
|
+
expect( @socket ).to receive( :recv ).
|
52
40
|
and_return( "59:7:headers,6:3:msg,]4:rows,29:25:21:signal sent to server,]]}" )
|
53
|
-
@control.stop.
|
41
|
+
expect( @control.stop ).to eq( [{ :msg => "signal sent to server" }] )
|
54
42
|
end
|
55
43
|
|
56
44
|
it "sends a 'reload' command to the control port when #reload is called" do
|
57
|
-
@socket.
|
58
|
-
@socket.
|
45
|
+
expect( @socket ).to receive( :send ).with( "12:6:reload,0:}]" )
|
46
|
+
expect( @socket ).to receive( :recv ).
|
59
47
|
and_return( "59:7:headers,6:3:msg,]4:rows,29:25:21:signal sent to server,]]}" )
|
60
|
-
@control.reload.
|
48
|
+
expect( @control.reload ).to eq( [{ :msg => "signal sent to server" }] )
|
61
49
|
end
|
62
50
|
|
63
51
|
it "sends a 'terminate' command to the control port when #terminate is called" do
|
64
|
-
@socket.
|
65
|
-
@socket.
|
52
|
+
expect( @socket ).to receive( :send ).with( "15:9:terminate,0:}]" )
|
53
|
+
expect( @socket ).to receive( :recv ).
|
66
54
|
and_return( "59:7:headers,6:3:msg,]4:rows,29:25:21:signal sent to server,]]}" )
|
67
|
-
@control.terminate.
|
55
|
+
expect( @control.terminate ).to eq( [{ :msg => "signal sent to server" }] )
|
68
56
|
end
|
69
57
|
|
70
58
|
it "sends a 'help' command to the control port when #help is called" do
|
71
|
-
@socket.
|
72
|
-
@socket.
|
59
|
+
expect( @socket ).to receive( :send ).with( "10:4:help,0:}]" )
|
60
|
+
expect( @socket ).to receive( :recv ).
|
73
61
|
and_return( "416:7:headers,14:4:name,4:help,]4:rows,376:35:4:stop" +
|
74
62
|
",24:stop the server (SIGINT),]30:6:reload,17:reload " +
|
75
63
|
"the server,]23:4:help,12:this command,]37:12:control" +
|
@@ -79,7 +67,7 @@ describe Mongrel2::Control do
|
|
79
67
|
"8:4:time,17:the server's time,]28:4:uuid,17:the serv" +
|
80
68
|
"er's uuid,]40:4:info,29:information about this serve" +
|
81
69
|
"r,]]}" )
|
82
|
-
@control.help.
|
70
|
+
expect( @control.help ).to eq([
|
83
71
|
{:name => "stop", :help => "stop the server (SIGINT)"},
|
84
72
|
{:name => "reload", :help => "reload the server"},
|
85
73
|
{:name => "help", :help => "this command"},
|
@@ -90,27 +78,27 @@ describe Mongrel2::Control do
|
|
90
78
|
{:name => "time", :help => "the server's time"},
|
91
79
|
{:name => "uuid", :help => "the server's uuid"},
|
92
80
|
{:name => "info", :help => "information about this server"}
|
93
|
-
]
|
81
|
+
])
|
94
82
|
end
|
95
83
|
|
96
84
|
it "sends a 'uuid' command to the control port when #uuid is called" do
|
97
|
-
@socket.
|
98
|
-
@socket.
|
85
|
+
expect( @socket ).to receive( :send ).with( "10:4:uuid,0:}]" )
|
86
|
+
expect( @socket ).to receive( :recv ).
|
99
87
|
and_return( "75:7:headers,7:4:uuid,]4:rows,44:40:36:34D8E57C-3E91" +
|
100
88
|
"-4F24-9BBE-0B53C1827CB4,]]}" )
|
101
|
-
@control.uuid.
|
89
|
+
expect( @control.uuid ).to eq( [{ :uuid => '34D8E57C-3E91-4F24-9BBE-0B53C1827CB4' }] )
|
102
90
|
end
|
103
91
|
|
104
92
|
it "sends an 'info' command to the control port when #info is called" do
|
105
|
-
@socket.
|
106
|
-
@socket.
|
93
|
+
expect( @socket ).to receive( :send ).with( "10:4:info,0:}]" )
|
94
|
+
expect( @socket ).to receive( :recv ).
|
107
95
|
and_return( "260:7:headers,92:4:port,9:bind_addr,4:uuid,6:chroot," +
|
108
96
|
"10:access_log,9:error_log,8:pid_file,16:default_host" +
|
109
97
|
"name,]4:rows,142:137:4:8113#7:0.0.0.0,36:34D8E57C-3E" +
|
110
98
|
"91-4F24-9BBE-0B53C1827CB4,2:./,18:.//logs/access.log" +
|
111
99
|
",15:/logs/error.log,18:./run/mongrel2.pid,9:localhos" +
|
112
100
|
"t,]]}" )
|
113
|
-
@control.info.
|
101
|
+
expect( @control.info ).to eq([{
|
114
102
|
:port => 8113,
|
115
103
|
:bind_addr => "0.0.0.0",
|
116
104
|
:uuid => "34D8E57C-3E91-4F24-9BBE-0B53C1827CB4",
|
@@ -119,14 +107,14 @@ describe Mongrel2::Control do
|
|
119
107
|
:error_log => "/logs/error.log",
|
120
108
|
:pid_file => "./run/mongrel2.pid",
|
121
109
|
:default_hostname => "localhost"
|
122
|
-
}]
|
110
|
+
}])
|
123
111
|
end
|
124
112
|
|
125
113
|
it "sends a 'status' command with a 'what' option set to 'tasks' to the control port " +
|
126
114
|
"when #tasklist is called" do
|
127
115
|
|
128
|
-
@socket.
|
129
|
-
@socket.
|
116
|
+
expect( @socket ).to receive( :send ).with( "28:6:status,15:4:what,5:tasks,}]" )
|
117
|
+
expect( @socket ).to receive( :recv ).
|
130
118
|
and_return( "343:7:headers,38:2:id,6:system,4:name,5:state,6:status," +
|
131
119
|
"]4:rows,279:38:1:1#5:false!6:SERVER,7:read fd,4:idle,]5" +
|
132
120
|
"1:1:2#5:false!12:Handler_task,12:read handler,4:idle,]5" +
|
@@ -134,55 +122,55 @@ describe Mongrel2::Control do
|
|
134
122
|
"8:1:4#5:false!7:control,12:read handler,7:running,]31:1" +
|
135
123
|
":5#5:false!6:ticker,0:,4:idle,]36:1:6#4:true!6:fdtask,5" +
|
136
124
|
":yield,5:ready,]]}" )
|
137
|
-
@control.tasklist.
|
125
|
+
expect( @control.tasklist ).to eq([
|
138
126
|
{:id=>1, :system=>false, :name=>"SERVER", :state=>"read fd", :status=>"idle"},
|
139
127
|
{:id=>2, :system=>false, :name=>"Handler_task", :state=>"read handler", :status=>"idle"},
|
140
128
|
{:id=>3, :system=>false, :name=>"Handler_task", :state=>"read handler", :status=>"idle"},
|
141
129
|
{:id=>4, :system=>false, :name=>"control", :state=>"read handler", :status=>"running"},
|
142
130
|
{:id=>5, :system=>false, :name=>"ticker", :state=>"", :status=>"idle"},
|
143
131
|
{:id=>6, :system=>true, :name=>"fdtask", :state=>"yield", :status=>"ready"}
|
144
|
-
]
|
132
|
+
])
|
145
133
|
end
|
146
134
|
|
147
135
|
it "sends an 'status' command with a 'what' option set to 'net' to the control port " +
|
148
136
|
"when #conn_status is called" do
|
149
137
|
|
150
|
-
@socket.
|
151
|
-
@socket.
|
138
|
+
expect( @socket ).to receive( :send ).with( "26:6:status,13:4:what,3:net,}]" )
|
139
|
+
expect( @socket ).to receive( :recv ).
|
152
140
|
and_return( "150:7:headers,86:2:id,2:fd,4:type,9:last_ping,9:last_read," +
|
153
141
|
"10:last_write,10:bytes_read,13:bytes_written,]4:rows,39:35" +
|
154
142
|
":1:2#2:38#1:1#1:0#1:0#1:0#3:405#1:0#]]}" )
|
155
|
-
@control.conn_status.
|
143
|
+
expect( @control.conn_status ).to eq([
|
156
144
|
{:id=>2, :fd=>38, :type=>1, :last_ping=>0, :last_read=>0, :last_write=>0,
|
157
145
|
:bytes_read=>405, :bytes_written=>0}
|
158
|
-
]
|
146
|
+
])
|
159
147
|
end
|
160
148
|
|
161
149
|
it "sends a 'time' command to the control port when #time is called" do
|
162
|
-
@socket.
|
163
|
-
@socket.
|
150
|
+
expect( @socket ).to receive( :send ).with( "10:4:time,0:}]" )
|
151
|
+
expect( @socket ).to receive( :recv ).
|
164
152
|
and_return( "49:7:headers,7:4:time,]4:rows,18:14:10:1315532674,]]}" )
|
165
|
-
@control.time.
|
153
|
+
expect( @control.time ).to eq( Time.at( 1315532674 ) )
|
166
154
|
end
|
167
155
|
|
168
156
|
it "sends a 'kill' command with an ID equal to the argument to the control port when #kill " +
|
169
157
|
"is called" do
|
170
|
-
@socket.
|
171
|
-
@socket.
|
172
|
-
@control.kill( 0 ).
|
158
|
+
expect( @socket ).to receive( :send ).with( "19:4:kill,9:2:id,1:0#}]" )
|
159
|
+
expect( @socket ).to receive( :recv ).and_return( "40:7:headers,9:6:status,]4:rows,8:5:2:OK,]]}" )
|
160
|
+
expect( @control.kill( 0 ) ).to eq( [{ :status => "OK" }] )
|
173
161
|
end
|
174
162
|
|
175
163
|
it "sends a 'control_stop' command to the control port when #info is called" do
|
176
|
-
@socket.
|
177
|
-
@socket.
|
164
|
+
expect( @socket ).to receive( :send ).with( "19:12:control_stop,0:}]" )
|
165
|
+
expect( @socket ).to receive( :recv ).
|
178
166
|
and_return( "63:7:headers,6:3:msg,]4:rows,33:29:25:stopping the control port,]]}" )
|
179
|
-
@control.control_stop.
|
167
|
+
expect( @control.control_stop ).to eq( [{:msg => "stopping the control port"}] )
|
180
168
|
end
|
181
169
|
|
182
170
|
|
183
171
|
it "raises an exception if the server responds with an error" do
|
184
|
-
@socket.
|
185
|
-
@socket.
|
172
|
+
expect( @socket ).to receive( :send ).with( "19:4:kill,9:2:id,1:0#}]" )
|
173
|
+
expect( @socket ).to receive( :recv ).
|
186
174
|
and_return( "61:4:code,16:INVALID_ARGUMENT,5:error,22:Invalid argument type.,}" )
|
187
175
|
|
188
176
|
expect {
|