swiftiply 0.6.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTORS +2 -0
- data/README.md +62 -0
- data/bin/{mongrel_rails → evented_mongrel_rails} +6 -14
- data/bin/swiftiplied_mongrel_rails +246 -0
- data/bin/swiftiply +136 -116
- data/bin/swiftiply_mongrel_rails +2 -2
- data/bin/swiftiplyctl +283 -0
- data/cleanup.sh +5 -0
- data/ext/deque/extconf.rb +162 -0
- data/ext/deque/swiftcore/rubymain.cpp +435 -0
- data/ext/fastfilereader/extconf.rb +2 -2
- data/ext/fastfilereader/mapper.cpp +2 -0
- data/ext/map/extconf.rb +161 -0
- data/ext/map/rubymain.cpp +500 -0
- data/ext/splaytree/extconf.rb +161 -0
- data/ext/splaytree/swiftcore/rubymain.cpp +580 -0
- data/ext/splaytree/swiftcore/splay_map.h +635 -0
- data/ext/splaytree/swiftcore/splay_set.h +575 -0
- data/ext/splaytree/swiftcore/splay_tree.h +1127 -0
- data/external/httpclient.rb +231 -0
- data/external/package.rb +13 -13
- data/setup.rb +18 -2
- data/src/swiftcore/Swiftiply.rb +417 -773
- data/src/swiftcore/Swiftiply/backend_protocol.rb +213 -0
- data/src/swiftcore/Swiftiply/cache_base.rb +49 -0
- data/src/swiftcore/Swiftiply/cache_base_mixin.rb +52 -0
- data/src/swiftcore/Swiftiply/cluster_managers/rest_based_cluster_manager.rb +9 -0
- data/src/swiftcore/Swiftiply/cluster_protocol.rb +70 -0
- data/src/swiftcore/Swiftiply/config.rb +370 -0
- data/src/swiftcore/Swiftiply/config/rest_updater.rb +26 -0
- data/src/swiftcore/Swiftiply/constants.rb +101 -0
- data/src/swiftcore/Swiftiply/content_cache_entry.rb +44 -0
- data/src/swiftcore/Swiftiply/content_response.rb +45 -0
- data/src/swiftcore/Swiftiply/control_protocol.rb +49 -0
- data/src/swiftcore/Swiftiply/dynamic_request_cache.rb +41 -0
- data/src/swiftcore/Swiftiply/etag_cache.rb +64 -0
- data/src/swiftcore/Swiftiply/file_cache.rb +46 -0
- data/src/swiftcore/Swiftiply/hash_cache_base.rb +22 -0
- data/src/swiftcore/Swiftiply/http_recognizer.rb +267 -0
- data/src/swiftcore/Swiftiply/loggers/Analogger.rb +21 -0
- data/src/swiftcore/Swiftiply/loggers/stderror.rb +13 -0
- data/src/swiftcore/Swiftiply/mocklog.rb +10 -0
- data/src/swiftcore/Swiftiply/proxy.rb +15 -0
- data/src/swiftcore/Swiftiply/proxy_backends/keepalive.rb +286 -0
- data/src/swiftcore/Swiftiply/proxy_backends/traditional.rb +286 -0
- data/src/swiftcore/Swiftiply/proxy_backends/traditional/redis_directory.rb +87 -0
- data/src/swiftcore/Swiftiply/proxy_backends/traditional/static_directory.rb +69 -0
- data/src/swiftcore/Swiftiply/proxy_bag.rb +716 -0
- data/src/swiftcore/Swiftiply/rest_based_cluster_manager.rb +15 -0
- data/src/swiftcore/Swiftiply/splay_cache_base.rb +21 -0
- data/src/swiftcore/Swiftiply/support_pagecache.rb +6 -3
- data/src/swiftcore/Swiftiply/swiftiply_2_http_proxy.rb +7 -0
- data/src/swiftcore/Swiftiply/swiftiply_client.rb +20 -5
- data/src/swiftcore/Swiftiply/version.rb +5 -0
- data/src/swiftcore/evented_mongrel.rb +26 -8
- data/src/swiftcore/hash.rb +43 -0
- data/src/swiftcore/method_builder.rb +28 -0
- data/src/swiftcore/streamer.rb +46 -0
- data/src/swiftcore/swiftiplied_mongrel.rb +91 -23
- data/src/swiftcore/types.rb +20 -3
- data/swiftiply.gemspec +14 -8
- data/test/TC_Deque.rb +152 -0
- data/test/TC_ProxyBag.rb +147 -166
- data/test/TC_Swiftiply.rb +576 -169
- data/test/TC_Swiftiply/mongrel/evented_hello.rb +1 -1
- data/test/TC_Swiftiply/mongrel/swiftiplied_hello.rb +1 -1
- data/test/TC_Swiftiply/test_serve_static_file_xsendfile/sendfile_client.rb +27 -0
- data/test/TC_Swiftiply/test_ssl/bin/validate_ssl_capability.rb +21 -0
- data/test/TC_Swiftiply/test_ssl/test.cert +16 -0
- data/test/TC_Swiftiply/test_ssl/test.key +15 -0
- data/{bin → test/bin}/echo_client +0 -0
- metadata +136 -94
- data/README +0 -126
- data/ext/swiftiply_parse/parse.rl +0 -90
data/test/TC_Swiftiply.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require 'external/test_support'
|
3
3
|
SwiftcoreTestSupport.set_src_dir
|
4
4
|
require 'rbconfig'
|
5
5
|
require 'net/http'
|
6
|
+
require 'net/https'
|
6
7
|
require 'swiftcore/Swiftiply'
|
7
8
|
require 'yaml'
|
8
9
|
|
9
|
-
class TC_Swiftiply < Test
|
10
|
+
class TC_Swiftiply < Minitest::Test
|
10
11
|
@@testdir = SwiftcoreTestSupport.test_dir(__FILE__)
|
11
|
-
Ruby = File.join(::
|
12
|
+
Ruby = File.join(::RbConfig::CONFIG['bindir'],::RbConfig::CONFIG['ruby_install_name']) << ::RbConfig::CONFIG['EXEEXT']
|
12
13
|
|
13
14
|
DeleteQueue = []
|
14
15
|
KillQueue = []
|
@@ -17,6 +18,12 @@ class TC_Swiftiply < Test::Unit::TestCase
|
|
17
18
|
cluster_address: 127.0.0.1
|
18
19
|
cluster_port: 29998
|
19
20
|
daemonize: false
|
21
|
+
epoll: true
|
22
|
+
descriptors: 20000
|
23
|
+
defaults:
|
24
|
+
logger:
|
25
|
+
type: stderror
|
26
|
+
log_level: 0
|
20
27
|
map:
|
21
28
|
- incoming:
|
22
29
|
- 127.0.0.1
|
@@ -29,6 +36,17 @@ ECONF
|
|
29
36
|
def get_url(hostname,port,url)
|
30
37
|
Net::HTTP.start(hostname,port) {|http| http.get(url)}
|
31
38
|
end
|
39
|
+
|
40
|
+
def get_url_https(hostname, port, url)
|
41
|
+
http = Net::HTTP.new(hostname, port)
|
42
|
+
http.use_ssl = true
|
43
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
44
|
+
http.start {http.request_get(url)}
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_url_1_0(hostname, port, url)
|
48
|
+
Net::HTTP.start(hostname,port) {|http| http.instance_variable_set('@curr_http_version','1.0'); http.get(url)}
|
49
|
+
end
|
32
50
|
|
33
51
|
def post_url(hostname,port,url,data = nil)
|
34
52
|
Net::HTTP.start(hostname,port) {|http| http.post(url,data)}
|
@@ -38,6 +56,24 @@ ECONF
|
|
38
56
|
Net::HTTP.start(hostname,port) {|http| http.delete(url)}
|
39
57
|
end
|
40
58
|
|
59
|
+
require "#{@@testdir}/../external/httpclient"
|
60
|
+
def httpclient(host, port, request, query_string)
|
61
|
+
r = nil
|
62
|
+
EventMachine.run do
|
63
|
+
http = EventMachine::Protocols::HttpClient.request(
|
64
|
+
:host => host,
|
65
|
+
:port => port,
|
66
|
+
:request => request,
|
67
|
+
:query_string => query_string
|
68
|
+
)
|
69
|
+
http.callback do |response|
|
70
|
+
r = response
|
71
|
+
EM.stop_event_loop
|
72
|
+
end
|
73
|
+
end
|
74
|
+
r
|
75
|
+
end
|
76
|
+
|
41
77
|
def setup
|
42
78
|
Dir.chdir(@@testdir)
|
43
79
|
SwiftcoreTestSupport.announce(:swiftiply_functional,"Functional Swiftiply Testing")
|
@@ -45,7 +81,7 @@ ECONF
|
|
45
81
|
|
46
82
|
def teardown
|
47
83
|
while f = DeleteQueue.pop do
|
48
|
-
File.delete f if f
|
84
|
+
File.delete f if f and FileTest.exist?(f)
|
49
85
|
end
|
50
86
|
|
51
87
|
while p = KillQueue.pop do
|
@@ -53,10 +89,107 @@ ECONF
|
|
53
89
|
Process.wait p if p
|
54
90
|
end
|
55
91
|
end
|
92
|
+
|
93
|
+
# Configure a Swiftiply, change the config, HUP it, and see if the changes
|
94
|
+
# are picked up.
|
95
|
+
|
96
|
+
def test_HUP
|
97
|
+
puts "\nTesting HUP handling"
|
98
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
99
|
+
dr = File.join(dc,'test_serve_static_file')
|
100
|
+
|
101
|
+
conf_file = File.join(dc,'test_HUP.conf')
|
102
|
+
File.open(conf_file,'w+') do |fh|
|
103
|
+
conf = YAML.load(ConfBase.to_yaml)
|
104
|
+
conf['map'].first.delete('docroot')
|
105
|
+
fh.write conf.to_yaml
|
106
|
+
end
|
107
|
+
|
108
|
+
DeleteQueue << conf_file
|
109
|
+
|
110
|
+
smallfile_name = "xyzzy"
|
111
|
+
smallfile_path = File.join(dr,smallfile_name)
|
112
|
+
File.open(smallfile_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
113
|
+
DeleteQueue << smallfile_path
|
114
|
+
|
115
|
+
swiftiply_pid = nil
|
116
|
+
KillQueue << swiftiply_pid = SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
117
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_HUP.conf"])
|
118
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
119
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999"])
|
120
|
+
sleep 1
|
121
|
+
|
122
|
+
# Normal request for a sanity check.
|
123
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
124
|
+
assert(response.body =~ /GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + '/GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
125
|
+
|
126
|
+
# Now rewrite the conf file to be a little different.
|
127
|
+
File.open(conf_file,'w+') {|fh| fh.write ConfBase.to_yaml }
|
128
|
+
|
129
|
+
# Reload the config
|
130
|
+
Process.kill 'SIGHUP',swiftiply_pid
|
131
|
+
|
132
|
+
sleep(1)
|
133
|
+
# This request should pull the file from the docroot, since it the
|
134
|
+
# docroot was not deleted from the config that was just read.
|
135
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
136
|
+
assert_equal("alfalfa leafcutter bee\n",response.body)
|
137
|
+
|
138
|
+
# Reload the config again, just to make sure we can do it twice;
|
139
|
+
# there was a bug reported about Swiftiply dying after the second HUP,
|
140
|
+
# so we want to make sure we are covered, here.
|
141
|
+
|
142
|
+
Process.kill 'SIGHUP',swiftiply_pid
|
143
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
144
|
+
assert_equal("alfalfa leafcutter bee\n",response.body,"Swiftiply failure on second HUP.")
|
145
|
+
|
146
|
+
# And because we're the suspicious types, let's do it a third tim, just to cover the bases.
|
147
|
+
Process.kill 'SIGHUP',swiftiply_pid
|
148
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
149
|
+
assert_equal("alfalfa leafcutter bee\n",response.body,"Swiftiply failure on second HUP.")
|
150
|
+
end
|
151
|
+
|
152
|
+
# Do some basic sanity tests of evented mongrel, and also run a simple
|
153
|
+
# perf test against evented mongrel and threaded mongrel.
|
56
154
|
|
155
|
+
def test_evented_mongrel
|
156
|
+
puts "\nTesting Evented Mongrel"
|
157
|
+
|
158
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => File.join('TC_Swiftiply','mongrel'),
|
159
|
+
:cmd => ["#{Ruby} -I../../../src threaded_hello.rb"])
|
160
|
+
sleep 1
|
161
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => File.join('TC_Swiftiply','mongrel'),
|
162
|
+
:cmd => ["#{Ruby} -I../../../src evented_hello.rb"])
|
163
|
+
|
164
|
+
sleep 1
|
165
|
+
|
166
|
+
response = get_url('127.0.0.1',29998,'/hello')
|
167
|
+
assert_equal("hello!\n",response.body)
|
168
|
+
|
169
|
+
response = get_url('127.0.0.1',29998,'/dir')
|
170
|
+
assert_equal("<html><head><title>Directory Listing",response.body[0..35])
|
171
|
+
|
172
|
+
ab = `which ab`.chomp
|
173
|
+
unless ab == ''
|
174
|
+
puts "\nThreaded Mongrel..."
|
175
|
+
rt = `#{ab} -n 10000 -c 25 http://127.0.0.1:29997/hello`
|
176
|
+
rt =~ /^(Requests per second.*)$/
|
177
|
+
rts = $1
|
178
|
+
puts "\nEvented Mongrel..."
|
179
|
+
re = `#{ab} -n 10000 -c 25 http://127.0.0.1:29998/hello`
|
180
|
+
re =~ /^(Requests per second.*)$/
|
181
|
+
res = $1
|
182
|
+
puts "\nThreaded Mongrel, no proxies, concurrency of 25\n#{rts}"
|
183
|
+
puts "Evented Mongrel, no proxies, concurrency of 25\n#{res}"
|
184
|
+
sleep 1
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
#####
|
57
189
|
# Test serving a small file (no chunked encoding) and a large file (chunked
|
58
190
|
# encoding).
|
59
|
-
|
191
|
+
#####
|
192
|
+
|
60
193
|
def test_serve_static_file
|
61
194
|
puts "\nTesting Static File Delivery"
|
62
195
|
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
@@ -64,7 +197,7 @@ ECONF
|
|
64
197
|
|
65
198
|
smallfile_name = "smallfile#{Time.now.to_i}"
|
66
199
|
smallfile_path = File.join(dr,smallfile_name)
|
67
|
-
File.open(smallfile_path,'w') {|fh| fh.puts "
|
200
|
+
File.open(smallfile_path,'w') {|fh| fh.puts "0123456789"*102}
|
68
201
|
DeleteQueue << smallfile_path
|
69
202
|
|
70
203
|
bigfile_name = "bigfile#{Time.now.to_i}"
|
@@ -73,23 +206,34 @@ ECONF
|
|
73
206
|
DeleteQueue << bigfile_path
|
74
207
|
|
75
208
|
conf_file = File.join(dc,'test_serve_static_file.conf')
|
76
|
-
|
209
|
+
conf = YAML.load(ConfBase.to_yaml)
|
210
|
+
|
211
|
+
File.open(conf_file,'w+') {|fh| fh.write conf.to_yaml}
|
77
212
|
DeleteQueue << conf_file
|
78
213
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
sleep 1
|
87
|
-
end
|
214
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
215
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_static_file.conf"])
|
216
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
217
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999"])
|
218
|
+
# Make sure everything has time to start, connect, etc... before
|
219
|
+
# the tests are executed.
|
220
|
+
sleep 1
|
88
221
|
|
89
222
|
response = get_url('127.0.0.1',29998,smallfile_name)
|
90
|
-
|
223
|
+
small_etag = response['ETag']
|
224
|
+
assert_equal("0123456789"*102+"\n",response.body)
|
225
|
+
|
226
|
+
# Make sure the file is retrieved if a proxy style request is used.
|
227
|
+
response = httpclient('127.0.0.1',29998,"http://127.0.0.1/#{smallfile_name}",'')
|
228
|
+
assert_equal("0123456789"*102+"\n",response[:content])
|
91
229
|
|
92
230
|
response = get_url('127.0.0.1',29998,bigfile_name)
|
231
|
+
big_etag = response['ETag']
|
232
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
233
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
234
|
+
assert_equal(79000,response.body.length)
|
235
|
+
|
236
|
+
response = get_url_1_0('127.0.0.1',29998,bigfile_name)
|
93
237
|
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
94
238
|
assert_equal("I am a duck. \n",response.body[-14..-1])
|
95
239
|
assert_equal(79000,response.body.length)
|
@@ -97,17 +241,312 @@ ECONF
|
|
97
241
|
# Hit it a bunch of times.
|
98
242
|
|
99
243
|
ab = `which ab`.chomp
|
244
|
+
#unless ab == ''
|
245
|
+
# r = `#{ab} -n 100000 -c 2 http://127.0.0.1:29998/#{smallfile_name}`
|
246
|
+
# r =~ /^(Requests per second.*)$/
|
247
|
+
# puts "10k 1020 byte files, concurrency of 25; no KeepAlive\n#{$1}\n"
|
248
|
+
#end
|
249
|
+
|
250
|
+
unless ab == ''
|
251
|
+
r = `#{ab} -n 100000 -c 25 -k http://127.0.0.1:29998/#{smallfile_name}`
|
252
|
+
r =~ /^(Requests per second.*)$/
|
253
|
+
puts r
|
254
|
+
puts "10k 1020 byte files, concurrency of 25; with KeepAlive\n#{$1}\n"
|
255
|
+
end
|
100
256
|
unless ab == ''
|
101
|
-
r = `#{ab} -n
|
257
|
+
r = `#{ab} -n 100000 -v 9 -c 25 -k -H 'If-None-Match: #{small_etag}' http://127.0.0.1:29998/#{smallfile_name}`
|
102
258
|
r =~ /^(Requests per second.*)$/
|
103
|
-
puts "10k files, concurrency of 25\n#{$1}"
|
259
|
+
puts "10k 1020 byte files with etag, concurrency of 25; with KeepAlive\n#{$1}\n"
|
260
|
+
end
|
261
|
+
unless ab == ''
|
262
|
+
r = `#{ab} -n 10000 -i -c 25 http://127.0.0.1:29998/#{smallfile_name}`
|
263
|
+
r =~ /^(Requests per second.*)$/
|
264
|
+
puts "10k HEAD requests, concurrency of 25\n#{$1}\n"
|
265
|
+
end
|
266
|
+
unless ab == ''
|
267
|
+
r = `#{ab} -n 20000 -c 25 -k http://127.0.0.1:29998/#{bigfile_name}`
|
268
|
+
r =~ /^(Requests per second.*)$/
|
269
|
+
puts "10k 78000 byte files, concurrency of 25; with KeepAlive\n#{$1}\n"
|
270
|
+
end
|
271
|
+
unless ab == ''
|
272
|
+
r = `#{ab} -n 20000 -c 25 -k -H 'If-None-Match: #{big_etag}' http://127.0.0.1:29998/#{bigfile_name}`
|
273
|
+
r =~ /^(Requests per second.*)$/
|
274
|
+
puts "10k 78000 byte files with etag, concurrency of 25; with KeepAlive\n#{$1}\n"
|
104
275
|
end
|
105
276
|
|
106
277
|
# And it is still correct?
|
107
278
|
response = get_url('127.0.0.1',29998,smallfile_name)
|
279
|
+
assert_equal("0123456789"*102+"\n",response.body)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_serve_static_file_caches
|
283
|
+
puts "\nTesting caches"
|
284
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
285
|
+
dr = File.join(dc,'test_serve_static_file')
|
286
|
+
|
287
|
+
smallfile_name = "smallfile#{Time.now.to_i}"
|
288
|
+
smallfile_path = File.join(dr,smallfile_name)
|
289
|
+
File.open(smallfile_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
290
|
+
DeleteQueue << smallfile_path
|
291
|
+
|
292
|
+
bigfile_name = "bigfile#{Time.now.to_i}"
|
293
|
+
bigfile_path = File.join(dr,bigfile_name)
|
294
|
+
File.open(bigfile_path,'w+') {|fh| fh.write("#{'I am a duck. ' * 6}\n" * 1000)}
|
295
|
+
DeleteQueue << bigfile_path
|
296
|
+
|
297
|
+
conf_file = File.join(dc,'test_serve_static_file.conf')
|
298
|
+
conf = YAML.load(ConfBase.to_yaml)
|
299
|
+
conf['logger'] ||= {}
|
300
|
+
conf['logger']['log_level'] = 3
|
301
|
+
conf['map'][0]['file_cache'] = {}
|
302
|
+
conf['map'][0]['file_cache']['window'] = 5
|
303
|
+
conf['map'][0]['logger'] = {}
|
304
|
+
conf['map'][0]['logger']['log_level'] = 3
|
305
|
+
conf['map'][0]['logger']['type'] = 'stderror'
|
306
|
+
|
307
|
+
File.open(conf_file,'w+') {|fh| fh.write conf.to_yaml}
|
308
|
+
DeleteQueue << conf_file
|
309
|
+
|
310
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
311
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_static_file.conf"])
|
312
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
313
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999"])
|
314
|
+
# Make sure everything has time to start, connect, etc... before
|
315
|
+
# the tests are executed.
|
316
|
+
sleep 1
|
317
|
+
|
318
|
+
response = get_url('127.0.0.1',29998,smallfile_name)
|
319
|
+
small_etag = response['ETag']
|
108
320
|
assert_equal("alfalfa leafcutter bee\n",response.body)
|
321
|
+
File.delete smallfile_path
|
322
|
+
|
323
|
+
response = get_url('127.0.0.1',29998,bigfile_name)
|
324
|
+
big_etag = response['ETag']
|
325
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
326
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
327
|
+
assert_equal(79000,response.body.length)
|
328
|
+
|
329
|
+
sleep 4
|
330
|
+
|
331
|
+
File.open(smallfile_path,'w') {|fh| fh.puts "alfalfa leafcutter bee too"}
|
332
|
+
|
333
|
+
response = get_url('127.0.0.1',29998,smallfile_name)
|
334
|
+
small_etag = response['ETag']
|
335
|
+
assert_equal("alfalfa leafcutter bee too\n",response.body)
|
336
|
+
end
|
337
|
+
|
338
|
+
#####
|
339
|
+
# Test the x-sendfile header support.
|
340
|
+
# Big and small files that do exist.
|
341
|
+
#####
|
342
|
+
|
343
|
+
def test_serve_static_file_xsendfile
|
344
|
+
puts "\nTesting Static File Delivery via X-Sendfile"
|
345
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
346
|
+
dr = File.join(dc,'test_serve_static_file_xsendfile')
|
347
|
+
|
348
|
+
smallfile1_name = "smallfile1#{Time.now.to_i}"
|
349
|
+
smallfile1_path = File.join(dr,'pub',smallfile1_name)
|
350
|
+
File.open(smallfile1_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
351
|
+
DeleteQueue << smallfile1_path
|
352
|
+
|
353
|
+
smallfile2_name = "smallfile2#{Time.now.to_i}"
|
354
|
+
smallfile2_path = File.join(dr,'priv',smallfile2_name)
|
355
|
+
File.open(smallfile2_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
356
|
+
DeleteQueue << smallfile2_path
|
357
|
+
|
358
|
+
bigfile1_name = "bigfile1#{Time.now.to_i}"
|
359
|
+
bigfile1_path = File.join(dr,'pub',bigfile1_name)
|
360
|
+
File.open(bigfile1_path,'w+') {|fh| fh.write("#{'I am a duck. ' * 6}\n" * 1000)}
|
361
|
+
DeleteQueue << bigfile1_path
|
362
|
+
|
363
|
+
bigfile2_name = "bigfile2#{Time.now.to_i}"
|
364
|
+
bigfile2_path = File.join(dr,'priv',bigfile2_name)
|
365
|
+
File.open(bigfile2_path,'w+') {|fh| fh.write("#{'I am a duck. ' * 6}\n" * 1000)}
|
366
|
+
DeleteQueue << bigfile2_path
|
367
|
+
|
368
|
+
conf = YAML.load(ConfBase.to_yaml)
|
369
|
+
conf['map'].first['docroot'] = "#{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/pub"
|
370
|
+
conf['map'].first['sendfileroot'] = "#{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/priv"
|
371
|
+
|
372
|
+
conf_file = File.join(dc,'test_serve_static_file_xsendfile.conf')
|
373
|
+
File.open(conf_file,'w+') {|fh| fh.write conf.to_yaml}
|
374
|
+
DeleteQueue << conf_file
|
375
|
+
|
376
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
377
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_static_file_xsendfile.conf"])
|
378
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
379
|
+
:cmd => ["#{Ruby} -I../../src #{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/sendfile_client.rb 127.0.0.1:29999"])
|
380
|
+
# Make sure everything has time to start, connect, etc... before
|
381
|
+
# the tests are executed.
|
382
|
+
sleep 1
|
383
|
+
|
384
|
+
response = get_url('127.0.0.1',29998,smallfile1_name)
|
385
|
+
small_etag = response['ETag']
|
386
|
+
assert_equal("alfalfa leafcutter bee\n",response.body)
|
387
|
+
|
388
|
+
response = get_url('127.0.0.1',29998,smallfile2_name)
|
389
|
+
small_etag = response['ETag']
|
390
|
+
assert_equal("alfalfa leafcutter bee\n",response.body)
|
391
|
+
|
392
|
+
response = get_url('127.0.0.1',29998,bigfile1_name)
|
393
|
+
big_etag = response['ETag']
|
394
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
395
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
396
|
+
assert_equal(79000,response.body.length)
|
397
|
+
|
398
|
+
response = get_url_1_0('127.0.0.1',29998,bigfile1_name)
|
399
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
400
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
401
|
+
assert_equal(79000,response.body.length)
|
402
|
+
|
403
|
+
response = get_url('127.0.0.1',29998,bigfile2_name)
|
404
|
+
big_etag = response['ETag']
|
405
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
406
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
407
|
+
assert_equal(79000,response.body.length)
|
408
|
+
|
409
|
+
response = get_url_1_0('127.0.0.1',29998,bigfile2_name)
|
410
|
+
assert_equal("I am a duck. I am a duck. ",response.body[0..25])
|
411
|
+
assert_equal("I am a duck. \n",response.body[-14..-1])
|
412
|
+
assert_equal(79000,response.body.length)
|
413
|
+
|
414
|
+
response = get_url('127.0.0.1',29998,'this_isnt_there')
|
415
|
+
assert_equal("this_isnt_there",response.to_hash['x-sendfile'].first)
|
416
|
+
assert(response.body =~ /Doing X-Sendfile to this_isnt_there/)
|
109
417
|
end
|
418
|
+
|
419
|
+
#####
|
420
|
+
# Test x-sendfile handling for a file that doesn't exist.
|
421
|
+
#####
|
422
|
+
|
423
|
+
def test_serve_static_file_xsendfile2
|
424
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
425
|
+
dr = File.join(dc,'test_serve_static_file_xsendfile')
|
426
|
+
|
427
|
+
smallfile2_name = "smallfile2#{Time.now.to_i}"
|
428
|
+
smallfile2_path = File.join(dr,'priv',smallfile2_name)
|
429
|
+
File.open(smallfile2_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
430
|
+
DeleteQueue << smallfile2_path
|
431
|
+
|
432
|
+
conf = YAML.load(ConfBase.to_yaml)
|
433
|
+
conf['map'].first['docroot'] = "#{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/pub"
|
434
|
+
conf['map'].first['sendfileroot'] = "#{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/priv"
|
435
|
+
conf['map'].first['enable_sendfile_404'] = 'true'
|
436
|
+
|
437
|
+
conf_file = File.join(dc,'test_serve_static_file_xsendfile.conf')
|
438
|
+
File.open(conf_file,'w+') {|fh| fh.write conf.to_yaml}
|
439
|
+
DeleteQueue << conf_file
|
440
|
+
|
441
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
442
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_static_file_xsendfile.conf"])
|
443
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
444
|
+
:cmd => ["#{Ruby} -I../../src #{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/sendfile_client.rb 127.0.0.1:29999"])
|
445
|
+
# Make sure everything has time to start, connect, etc... before
|
446
|
+
# the tests are executed.
|
447
|
+
sleep 1
|
448
|
+
|
449
|
+
response = get_url('127.0.0.1',29998,smallfile2_name)
|
450
|
+
small_etag = response['ETag']
|
451
|
+
assert_equal("alfalfa leafcutter bee\n",response.body)
|
452
|
+
|
453
|
+
response = get_url('127.0.0.1',29998,'this_isnt_there')
|
454
|
+
assert(Net::HTTPNotFound === response)
|
455
|
+
assert(response.body =~ /this_isnt_there could not be found/)
|
456
|
+
end
|
457
|
+
|
458
|
+
#####
|
459
|
+
# Setup an SSL connection and test a couple requests that use SSL.
|
460
|
+
#####
|
461
|
+
|
462
|
+
def test_ssl
|
463
|
+
puts "\nTesting SSL"
|
464
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
465
|
+
dr = File.join(dc,'test_ssl')
|
466
|
+
|
467
|
+
# Before proceding with testing, the code here should determine if the
|
468
|
+
# EventMachine installed on the system has SSL support built. If it
|
469
|
+
# does not, don't run the tests. Instead, report on this fact and
|
470
|
+
# point them at some information about how to reinstall EM so that it
|
471
|
+
# does support ssl.
|
472
|
+
|
473
|
+
print "Testing whether SSL is available..."
|
474
|
+
Thread.new do
|
475
|
+
sleep 1
|
476
|
+
print '..'
|
477
|
+
STDOUT.flush
|
478
|
+
sleep 1
|
479
|
+
print '..'
|
480
|
+
STDOUT.flush
|
481
|
+
sleep 1
|
482
|
+
print '..'
|
483
|
+
STDOUT.flush
|
484
|
+
sleep 1
|
485
|
+
print '..'
|
486
|
+
STDOUT.flush
|
487
|
+
http = Net::HTTP.new('127.0.0.1',3333)
|
488
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
489
|
+
http.use_ssl
|
490
|
+
http.start {http.request_get('/')}
|
491
|
+
puts '..'
|
492
|
+
end
|
493
|
+
|
494
|
+
ssl_available = system("#{Ruby} TC_Swiftiply/test_ssl/bin/validate_ssl_capability.rb")
|
495
|
+
|
496
|
+
if ssl_available
|
497
|
+
puts " SSL is available. Continuing."
|
498
|
+
else
|
499
|
+
puts "\n\n\n!!! Notice !!!"
|
500
|
+
puts "\nSSL does not appear to be available in your version of EventMachine."
|
501
|
+
puts "This is probably because it could not find the openssl libraries while compiling."
|
502
|
+
puts "If you do not have these libraries, install them, then rebuild/reinstall"
|
503
|
+
puts "EventMachine. If you do have them, you should report this as a bug to the"
|
504
|
+
puts "EventMachine project, with details about your system, library locations, etc...,"
|
505
|
+
puts "so that they can fix the build process."
|
506
|
+
puts "\nSkipping SSL tests."
|
507
|
+
return
|
508
|
+
end
|
509
|
+
|
510
|
+
smallfile_name = "smallfile#{Time.now.to_i}"
|
511
|
+
smallfile_path = File.join(dr,'pub',smallfile_name)
|
512
|
+
File.open(smallfile_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
513
|
+
DeleteQueue << smallfile_path
|
514
|
+
|
515
|
+
conf = YAML.load(ConfBase.to_yaml)
|
516
|
+
conf['map'].first['docroot'] = "#{@@testdir}/TC_Swiftiply/test_ssl/pub"
|
517
|
+
conf['ssl'] = []
|
518
|
+
conf['ssl'] << {'at' => '127.0.0.1:29998', 'certfile' => "#{@@testdir}/TC_Swiftiply/test_ssl/test.cert", 'keyfile' => "#{@@testdir}/TC_Swiftiply/test_ssl/test.key"}
|
519
|
+
conf['map'].first['sendfileroot'] = "#{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/priv"
|
520
|
+
conf['map'].first['enable_sendfile_404'] = 'true'
|
521
|
+
|
522
|
+
conf_file = File.join(dc,'test_ssl.conf')
|
523
|
+
File.open(conf_file,'w+') {|fh| fh.write conf.to_yaml}
|
524
|
+
DeleteQueue << conf_file
|
525
|
+
|
526
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
527
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_ssl.conf"])
|
528
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
529
|
+
:cmd => ["#{Ruby} -I../../src #{@@testdir}/TC_Swiftiply/test_serve_static_file_xsendfile/sendfile_client.rb 127.0.0.1:29999"])
|
530
|
+
# Make sure everything has time to start, connect, etc... before
|
531
|
+
# the tests are executed.
|
532
|
+
sleep 1
|
110
533
|
|
534
|
+
response = get_url_https('127.0.0.1',29998,smallfile_name)
|
535
|
+
small_etag = response['ETag']
|
536
|
+
assert_equal("alfalfa leafcutter bee\n",response.body)
|
537
|
+
|
538
|
+
response = get_url_https('127.0.0.1',29998,'this_isnt_there')
|
539
|
+
assert(Net::HTTPNotFound === response)
|
540
|
+
assert(response.body =~ /this_isnt_there could not be found/)
|
541
|
+
|
542
|
+
#ab = `which ab`.chomp
|
543
|
+
#unless ab == ''
|
544
|
+
# r = `#{ab} -n 20000 -c 25 https://127.0.0.1:29998/#{smallfile_name}`
|
545
|
+
# r =~ /^(Requests per second.*)$/
|
546
|
+
# puts "10k 22 byte files through SSL, concurrency of 25\n#{$1}\n"
|
547
|
+
#end
|
548
|
+
end
|
549
|
+
|
111
550
|
def test_serve_static_file_from_cachedir
|
112
551
|
puts "\nTesting Static File Delivery From Cachedir"
|
113
552
|
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
@@ -143,15 +582,13 @@ ECONF
|
|
143
582
|
end
|
144
583
|
DeleteQueue << conf_file
|
145
584
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
sleep 1
|
154
|
-
end
|
585
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
586
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_static_file_from_cachedir.conf"])
|
587
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
588
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999"])
|
589
|
+
# Make sure everything has time to start, connect, etc... before
|
590
|
+
# the tests are executed.
|
591
|
+
sleep 1
|
155
592
|
|
156
593
|
response = get_url('127.0.0.1',29998,smallfile_name)
|
157
594
|
assert_equal("alfalfa leafcutter bee\n",response.body)
|
@@ -180,33 +617,37 @@ ECONF
|
|
180
617
|
File.open(conf_file,'w+') {|fh| fh.write ConfBase.to_yaml}
|
181
618
|
DeleteQueue << conf_file
|
182
619
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
620
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
621
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_normal_proxy.conf"])
|
622
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
623
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999"])
|
624
|
+
sleep 1
|
625
|
+
|
190
626
|
|
191
627
|
# Normal request
|
192
628
|
response = get_url('127.0.0.1',29998,'/xyzzy')
|
193
|
-
|
629
|
+
assert(response.body =~ /GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + '/GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
194
630
|
|
195
631
|
# With query string params.
|
196
632
|
response = get_url('127.0.0.1',29998,'/foo/bar/bam?Q=1234')
|
197
|
-
|
633
|
+
assert(response.body =~ /GET \/foo\/bar\/bam\?Q=1234 HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + 'GET /foo/bar/bam?Q=1234 HTTP/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
198
634
|
|
199
635
|
# POST request
|
200
636
|
response = post_url('127.0.0.1',29998,'/xyzzy')
|
201
|
-
|
637
|
+
assert(response.body =~ /POST \/xyzzy HTTP\/1.1\r\n.*x-www-form-urlencoded\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + '/POST /xyzzy HTTP/1.1\r\n.*x-www-form-urlencoded\r\n\r\n/m')
|
202
638
|
|
203
639
|
# And another verb; different verbs should be irrelevant
|
204
640
|
response = delete_url('127.0.0.1',29998,'/xyzzy')
|
205
|
-
|
641
|
+
assert(response.body =~ /DELETE \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + 'DELETE /xyzzy HTTP/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
206
642
|
|
207
643
|
# A non-matching hostname, to trigger default handling
|
208
644
|
response = get_url('localhost',29998,'/xyzzy')
|
209
|
-
|
645
|
+
assert(response.body =~ /GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: localhost:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + 'GET /xyzzy HTTP/1.1\r\n.*\r\nHost: localhost:29998\r\n\r\n/m')
|
646
|
+
|
647
|
+
# A very large url
|
648
|
+
u = '/abcdefghijklmnopqrstuvwxyz'*100
|
649
|
+
response = get_url('127.0.0.1',29998,u)
|
650
|
+
assert(response.body =~ /GET #{u} HTTP\/1.1.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + 'GET #{u} HTTP/1.1.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
210
651
|
end
|
211
652
|
|
212
653
|
# Test redeployable requests.
|
@@ -225,13 +666,11 @@ ECONF
|
|
225
666
|
DeleteQueue << conf_file
|
226
667
|
|
227
668
|
secpid = nil
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
sleep 1
|
234
|
-
end
|
669
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
670
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_redeployable.conf"])
|
671
|
+
secpid = SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
672
|
+
:cmd => ["#{Ruby} -I../../src slow_echo_client 127.0.0.1:29999"])
|
673
|
+
sleep 1
|
235
674
|
|
236
675
|
response = nil
|
237
676
|
urlthread = Thread.start {response = get_url('127.0.0.1',29998,'/slo_gin_fizz')}
|
@@ -240,14 +679,11 @@ ECONF
|
|
240
679
|
|
241
680
|
Process.kill "SIGKILL",secpid
|
242
681
|
secpid = nil
|
243
|
-
|
244
|
-
|
245
|
-
secpid = SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
246
|
-
:cmd => ["#{Ruby} -I../../src slow_echo_client 127.0.0.1:29999"])
|
247
|
-
end
|
682
|
+
secpid = SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
683
|
+
:cmd => ["#{Ruby} -I../../src slow_echo_client 127.0.0.1:29999"])
|
248
684
|
|
249
685
|
urlthread.join
|
250
|
-
|
686
|
+
assert(response.body =~ /GET \/slo_gin_fizz HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + 'GET /slo_gin_fizz HTTP/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
251
687
|
|
252
688
|
sleep 1
|
253
689
|
|
@@ -257,9 +693,7 @@ ECONF
|
|
257
693
|
|
258
694
|
# First, make sure that an ininterrupted request of this size is handled.
|
259
695
|
|
260
|
-
|
261
|
-
response = post_url('127.0.0.1',29998,'/slo_gin_fizz',bigdata)
|
262
|
-
end
|
696
|
+
response = post_url('127.0.0.1',29998,'/slo_gin_fizz',bigdata)
|
263
697
|
|
264
698
|
response.body =~ /(xxxxx*)/
|
265
699
|
xs_len = $1.length
|
@@ -278,17 +712,15 @@ ECONF
|
|
278
712
|
|
279
713
|
Process.kill "SIGKILL",secpid
|
280
714
|
secpid = nil
|
281
|
-
|
282
|
-
|
283
|
-
:cmd => ["#{Ruby} -I../../src slow_echo_client 127.0.0.1:29999"])
|
284
|
-
end
|
715
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
716
|
+
:cmd => ["#{Ruby} -I../../src slow_echo_client 127.0.0.1:29999"])
|
285
717
|
|
286
|
-
assert_raise(EOFError) do
|
287
|
-
# Net::HTTP should have blown up trying to get a result. The
|
288
|
-
# request was too big to be redeployed, so the connection should
|
289
|
-
# have been dropped with nothing returned.
|
290
|
-
urlthread.join
|
291
|
-
end
|
718
|
+
# assert_raise(EOFError) do
|
719
|
+
# # Net::HTTP should have blown up trying to get a result. The
|
720
|
+
# # request was too big to be redeployed, so the connection should
|
721
|
+
# # have been dropped with nothing returned.
|
722
|
+
# urlthread.join
|
723
|
+
# end
|
292
724
|
ensure
|
293
725
|
Process.kill("SIGKILL",secpid) if secpid
|
294
726
|
end
|
@@ -306,74 +738,86 @@ ECONF
|
|
306
738
|
end
|
307
739
|
DeleteQueue << conf_file
|
308
740
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
sleep 1
|
315
|
-
end
|
741
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
742
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_normal_proxy_with_authentication.conf"])
|
743
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
744
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999 abcdef1234"])
|
745
|
+
sleep 1
|
316
746
|
|
317
747
|
# Normal request
|
318
748
|
response = get_url('127.0.0.1',29998,'/xyzzy')
|
319
|
-
|
749
|
+
assert(response.body =~ /GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m, "Got #{response.body.inspect}, expected to match " + '/GET \/xyzzy HTTP\/1.1\r\n.*\r\nHost: 127.0.0.1:29998\r\n\r\n/m')
|
320
750
|
end
|
321
|
-
|
322
|
-
def test_sensible_error1
|
323
|
-
puts "\n---------------------------------"
|
324
|
-
puts "| Raising an error; this is OK! |"
|
325
|
-
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
326
|
-
sleep 1
|
327
751
|
|
752
|
+
def test_http_404_error
|
753
|
+
puts "\nTesting Request for Unknown Host, No Default (404 Error situation)"
|
328
754
|
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
329
755
|
dr = dc
|
330
756
|
|
331
|
-
conf_file = File.join(dc,'
|
332
|
-
File.open(conf_file,'w+')
|
757
|
+
conf_file = File.join(dc,'test_404_error.conf')
|
758
|
+
File.open(conf_file,'w+') do |fh|
|
759
|
+
conf = YAML.load(ConfBase.to_yaml)
|
760
|
+
conf['map'].first['default'] = false
|
761
|
+
conf['map'].first['incoming'] = ["localhost"]
|
762
|
+
fh.write conf.to_yaml
|
763
|
+
end
|
764
|
+
|
333
765
|
DeleteQueue << conf_file
|
334
766
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
767
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
768
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_404_error.conf"])
|
769
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
770
|
+
:cmd => ["#{Ruby} -I../../src ../bin/echo_client 127.0.0.1:29999 abcdef1234"])
|
771
|
+
sleep 1
|
772
|
+
|
773
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
774
|
+
assert_equal("404",response.header.code)
|
343
775
|
end
|
344
|
-
|
345
|
-
def
|
346
|
-
puts "\nTesting
|
776
|
+
|
777
|
+
def test_http_503_error
|
778
|
+
puts "\nTesting Request when server unavailable (503 error situation)"
|
779
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
780
|
+
dr = dc
|
347
781
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
:cmd => ["#{Ruby} -I../../../src threaded_hello.rb"])
|
782
|
+
conf_file = File.join(dc,'test_404_error.conf')
|
783
|
+
File.open(conf_file,'w+') do |fh|
|
784
|
+
conf = YAML.load(ConfBase.to_yaml)
|
785
|
+
fh.write conf.to_yaml
|
353
786
|
end
|
354
787
|
|
788
|
+
DeleteQueue << conf_file
|
789
|
+
|
790
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
791
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_404_error.conf"])
|
355
792
|
sleep 1
|
356
793
|
|
357
|
-
response = get_url('127.0.0.1',29998,'/
|
358
|
-
assert_equal("
|
794
|
+
response = get_url('127.0.0.1',29998,'/xyzzy')
|
795
|
+
assert_equal("503",response.header.code)
|
796
|
+
end
|
797
|
+
|
798
|
+
def test_sensible_error1
|
799
|
+
puts "\n---------------------------------------------------------------"
|
800
|
+
puts "| Raising an error; this is OK! |"
|
801
|
+
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
802
|
+
sleep 1
|
803
|
+
|
804
|
+
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
805
|
+
dr = dc
|
359
806
|
|
360
|
-
|
361
|
-
|
807
|
+
conf_file = File.join(dc,'test_sensible_error1.conf')
|
808
|
+
File.open(conf_file,'w+') {|fh| fh.write ConfBase.to_yaml }
|
809
|
+
DeleteQueue << conf_file
|
362
810
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
puts "\nThreaded Mongrel, no proxies, concurrency of 25\n#{rts}"
|
374
|
-
puts "Evented Mongrel, no proxies, concurrency of 25\n#{res}"
|
375
|
-
sleep 1
|
376
|
-
end
|
811
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
812
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_sensible_error1.conf"])
|
813
|
+
sleep 1
|
814
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
815
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_sensible_error1.conf"])
|
816
|
+
sleep 1
|
817
|
+
puts "\n---------------------------------------------------------------"
|
818
|
+
puts "| The above exception was just a test. It should have started |"
|
819
|
+
puts "| with: \"The listener on 127.0.0.1:29998 could not be started.\" |"
|
820
|
+
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
377
821
|
end
|
378
822
|
|
379
823
|
def test_swiftiplied_mongrel
|
@@ -386,17 +830,19 @@ ECONF
|
|
386
830
|
File.open(conf_file,'w+') {|fh| fh.write ConfBase.to_yaml}
|
387
831
|
DeleteQueue << conf_file
|
388
832
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
end
|
833
|
+
kq = []
|
834
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
835
|
+
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_serve_mongrel.conf"])
|
836
|
+
sleep 1
|
837
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => File.join('TC_Swiftiply','mongrel'),
|
838
|
+
:cmd => ["#{Ruby} -I../../../src swiftiplied_hello.rb"])
|
839
|
+
KillQueue << SwiftcoreTestSupport::create_process(:dir => File.join('TC_Swiftiply','mongrel'),
|
840
|
+
:cmd => ["#{Ruby} -I../../../src swiftiplied_hello.rb"])
|
841
|
+
sleep 1
|
399
842
|
|
843
|
+
response = httpclient('127.0.0.1',29998,"http://127.0.0.1",'')
|
844
|
+
assert(response[:headers].any? {|x| x =~ /404\s+not\s+found/i})
|
845
|
+
|
400
846
|
response = get_url('127.0.0.1',29998,'/hello')
|
401
847
|
assert_equal("hello!\n",response.body)
|
402
848
|
|
@@ -409,50 +855,11 @@ ECONF
|
|
409
855
|
r =~ /^(Requests per second.*)$/
|
410
856
|
puts "Swiftiply -> Swiftiplied Mongrel, concurrency of 25\n#{$1}"
|
411
857
|
end
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
dc = File.join(Dir.pwd,'TC_Swiftiply')
|
417
|
-
dr = File.join(dc,'test_serve_static_file')
|
418
|
-
|
419
|
-
conf_file = File.join(dc,'test_HUP.conf')
|
420
|
-
File.open(conf_file,'w+') do |fh|
|
421
|
-
conf = YAML.load(ConfBase.to_yaml)
|
422
|
-
conf['map'].first.delete('docroot')
|
423
|
-
fh.write conf.to_yaml
|
424
|
-
end
|
425
|
-
DeleteQueue << conf_file
|
426
|
-
|
427
|
-
smallfile_name = "xyzzy"
|
428
|
-
smallfile_path = File.join(dr,smallfile_name)
|
429
|
-
File.open(smallfile_path,'w') {|fh| fh.puts "alfalfa leafcutter bee"}
|
430
|
-
DeleteQueue << smallfile_path
|
431
|
-
|
432
|
-
swiftiply_pid = nil
|
433
|
-
assert_nothing_raised("setup failed") do
|
434
|
-
KillQueue << swiftiply_pid = SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
435
|
-
:cmd => ["#{Ruby} -I../../src ../../bin/swiftiply -c test_HUP.conf"])
|
436
|
-
KillQueue << SwiftcoreTestSupport::create_process(:dir => 'TC_Swiftiply',
|
437
|
-
:cmd => ["#{Ruby} -I../../src ../../bin/echo_client 127.0.0.1:29999"])
|
438
|
-
sleep 1
|
858
|
+
unless ab == ''
|
859
|
+
r = `#{ab} -n 100000 -k -c 25 http://127.0.0.1:29998/hello`
|
860
|
+
r =~ /^(Requests per second.*)$/
|
861
|
+
puts "Swiftiply -> Swiftiplied Mongrel, concurrency of 25 with Keep-Alive\n#{$1}"
|
439
862
|
end
|
440
|
-
|
441
|
-
# Normal request for a sanity check.
|
442
|
-
response = get_url('127.0.0.1',29998,'/xyzzy')
|
443
|
-
assert_equal("GET /xyzzy HTTP/1.1\r\nAccept: */*\r\nHost: 127.0.0.1:29998\r\n\r\n",response.body)
|
444
|
-
|
445
|
-
# Now rewrite the conf file to be a little different.
|
446
|
-
File.open(conf_file,'w+') {|fh| fh.write ConfBase.to_yaml }
|
447
|
-
|
448
|
-
# Reload the config
|
449
|
-
Process.kill 'SIGHUP',swiftiply_pid
|
450
|
-
|
451
|
-
# This request should pull the file from the docroot, since it the
|
452
|
-
# docroot was not deleted from the config that was just read.
|
453
|
-
response = get_url('127.0.0.1',29998,'/xyzzy')
|
454
|
-
|
455
|
-
assert_equal("alfalfa leafcutter bee\n",response.body)
|
456
863
|
end
|
457
864
|
|
458
865
|
end
|