hayabusa 0.0.25 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
data/hayabusa.gemspec DELETED
@@ -1,168 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: hayabusa 0.0.25 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "hayabusa"
9
- s.version = "0.0.25"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Kasper Johansen"]
14
- s.date = "2014-12-06"
15
- s.description = "A threadded web/app-server that focuses on threadding, shared ressources, speed and more."
16
- s.email = "k@spernj.org"
17
- s.executables = ["check_running.rb", "hayabusa_benchmark.rb", "hayabusa_cgi.rb", "hayabusa_fcgi.fcgi", "hayabusa_fcgi.rb", "hayabusa_fcgi_server.rb", "hayabusa_spec_restart.rb", "knjappserver_start.rb"]
18
- s.extra_rdoc_files = [
19
- "LICENSE.txt",
20
- "README.md"
21
- ]
22
- s.files = [
23
- ".document",
24
- ".rspec",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE.txt",
28
- "README.md",
29
- "Rakefile",
30
- "VERSION",
31
- "bin/check_running.rb",
32
- "bin/hayabusa_benchmark.rb",
33
- "bin/hayabusa_cgi.rb",
34
- "bin/hayabusa_fcgi.fcgi",
35
- "bin/hayabusa_fcgi.rb",
36
- "bin/hayabusa_fcgi_server.rb",
37
- "bin/hayabusa_spec_restart.rb",
38
- "bin/knjappserver_start.rb",
39
- "conf/apache2_cgi_rhtml_conf.conf",
40
- "conf/apache2_fcgi_rhtml_conf.conf",
41
- "conf/apache2_hayabusa_conf.conf",
42
- "hayabusa.gemspec",
43
- "lib/hayabusa.rb",
44
- "lib/hayabusa_cgi.rb",
45
- "lib/hayabusa_cgi_session.rb",
46
- "lib/hayabusa_cgi_tools.rb",
47
- "lib/hayabusa_client_session.rb",
48
- "lib/hayabusa_custom_io.rb",
49
- "lib/hayabusa_database.rb",
50
- "lib/hayabusa_erb_handler.rb",
51
- "lib/hayabusa_ext/cleaner.rb",
52
- "lib/hayabusa_ext/cmdline.rb",
53
- "lib/hayabusa_ext/errors.rb",
54
- "lib/hayabusa_ext/logging.rb",
55
- "lib/hayabusa_ext/mailing.rb",
56
- "lib/hayabusa_ext/sessions.rb",
57
- "lib/hayabusa_ext/threadding.rb",
58
- "lib/hayabusa_ext/threadding_timeout.rb",
59
- "lib/hayabusa_ext/translations.rb",
60
- "lib/hayabusa_ext/web.rb",
61
- "lib/hayabusa_fcgi.rb",
62
- "lib/hayabusa_fcgi_server.rb",
63
- "lib/hayabusa_http_server.rb",
64
- "lib/hayabusa_http_session.rb",
65
- "lib/hayabusa_http_session_contentgroup.rb",
66
- "lib/hayabusa_http_session_page_environment.rb",
67
- "lib/hayabusa_http_session_post_multipart.rb",
68
- "lib/hayabusa_http_session_request.rb",
69
- "lib/hayabusa_http_session_response.rb",
70
- "lib/hayabusa_models.rb",
71
- "lib/kernel_ext/gettext_methods.rb",
72
- "lib/kernel_ext/magic_methods.rb",
73
- "lib/models/log.rb",
74
- "lib/models/log_access.rb",
75
- "lib/models/log_data.rb",
76
- "lib/models/log_data_link.rb",
77
- "lib/models/log_data_value.rb",
78
- "lib/models/log_link.rb",
79
- "lib/models/session.rb",
80
- "pages/benchmark.rhtml",
81
- "pages/benchmark_print.rhtml",
82
- "pages/benchmark_simple.rhtml",
83
- "pages/benchmark_threadded_content.rhtml",
84
- "pages/config_cgi.rb",
85
- "pages/config_fcgi.rb",
86
- "pages/debug_database_connections.rhtml",
87
- "pages/debug_http_sessions.rhtml",
88
- "pages/debug_memory_usage.rhtml",
89
- "pages/error_notfound.rhtml",
90
- "pages/image.png",
91
- "pages/logs_latest.rhtml",
92
- "pages/logs_show.rhtml",
93
- "pages/spec.rhtml",
94
- "pages/spec_exit.rhtml",
95
- "pages/spec_multiple_threads.rhtml",
96
- "pages/spec_sleeper.rhtml",
97
- "pages/spec_test_multiple_clients.rhtml",
98
- "pages/spec_thread_joins.rhtml",
99
- "pages/spec_threadded_content.rhtml",
100
- "pages/spec_vars_get.rhtml",
101
- "pages/spec_vars_header.rhtml",
102
- "pages/spec_vars_post.rhtml",
103
- "pages/spec_vars_post_fileupload.rhtml",
104
- "pages/testpic.jpeg",
105
- "pages/tests.rhtml",
106
- "pages/threadded_content_test.rhtml",
107
- "spec/fcgi_multiple_processes_spec.rb",
108
- "spec/hayabusa_spec.rb",
109
- "spec/spec_helper.rb",
110
- "spec/test_upload.xlsx"
111
- ]
112
- s.homepage = "http://github.com/kaspernj/hayabusa"
113
- s.licenses = ["MIT"]
114
- s.rubygems_version = "2.4.0"
115
- s.summary = "A threadded web/app-server that supports stand-alone, CGI and FCGI-modes."
116
-
117
- if s.respond_to? :specification_version then
118
- s.specification_version = 4
119
-
120
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
121
- s.add_runtime_dependency(%q<knjrbfw>, [">= 0"])
122
- s.add_runtime_dependency(%q<erubis>, [">= 0"])
123
- s.add_runtime_dependency(%q<mail>, [">= 0"])
124
- s.add_runtime_dependency(%q<datet>, [">= 0"])
125
- s.add_runtime_dependency(%q<http2>, [">= 0"])
126
- s.add_runtime_dependency(%q<tpool>, [">= 0"])
127
- s.add_runtime_dependency(%q<ruby_process>, [">= 0"])
128
- s.add_development_dependency(%q<json>, [">= 0"])
129
- s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
130
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
131
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.8"])
132
- s.add_development_dependency(%q<rmagick>, [">= 0"])
133
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
134
- s.add_development_dependency(%q<php4r>, [">= 0"])
135
- else
136
- s.add_dependency(%q<knjrbfw>, [">= 0"])
137
- s.add_dependency(%q<erubis>, [">= 0"])
138
- s.add_dependency(%q<mail>, [">= 0"])
139
- s.add_dependency(%q<datet>, [">= 0"])
140
- s.add_dependency(%q<http2>, [">= 0"])
141
- s.add_dependency(%q<tpool>, [">= 0"])
142
- s.add_dependency(%q<ruby_process>, [">= 0"])
143
- s.add_dependency(%q<json>, [">= 0"])
144
- s.add_dependency(%q<rspec>, [">= 2.3.0"])
145
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
146
- s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
147
- s.add_dependency(%q<rmagick>, [">= 0"])
148
- s.add_dependency(%q<sqlite3>, [">= 0"])
149
- s.add_dependency(%q<php4r>, [">= 0"])
150
- end
151
- else
152
- s.add_dependency(%q<knjrbfw>, [">= 0"])
153
- s.add_dependency(%q<erubis>, [">= 0"])
154
- s.add_dependency(%q<mail>, [">= 0"])
155
- s.add_dependency(%q<datet>, [">= 0"])
156
- s.add_dependency(%q<http2>, [">= 0"])
157
- s.add_dependency(%q<tpool>, [">= 0"])
158
- s.add_dependency(%q<ruby_process>, [">= 0"])
159
- s.add_dependency(%q<json>, [">= 0"])
160
- s.add_dependency(%q<rspec>, [">= 2.3.0"])
161
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
162
- s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
163
- s.add_dependency(%q<rmagick>, [">= 0"])
164
- s.add_dependency(%q<sqlite3>, [">= 0"])
165
- s.add_dependency(%q<php4r>, [">= 0"])
166
- end
167
- end
168
-
@@ -1,104 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Hayabusa" do
4
- it "should handle sessions correctly under stressed conditions" do
5
- require "knjrbfw"
6
- Knj.gem_require(:Http2)
7
- require "json"
8
-
9
- ts = []
10
- errs = []
11
-
12
- 1.upto(10) do |t_i|
13
- ts << Thread.new do
14
- if t_i == 1
15
- debug = true
16
- else
17
- debug = false
18
- end
19
-
20
- begin
21
- session_id = nil
22
- hayabusa_session_id = nil
23
- session_hash_obj_id = nil
24
-
25
- Http2.new(:host => "localhost", :user_agent => "Client#{t_i}", :debug => false) do |http|
26
- 1.upto(25) do |request_i|
27
- res = http.get(:url => "hayabusa_fcgi_test/spec_multiple_threads.rhtml")
28
-
29
- begin
30
- data_json = JSON.parse(res.body)
31
- rescue => e
32
- raise "Could not parse result as JSON: '#{res.body}'."
33
- end
34
-
35
- data = {}
36
- data_json.each do |key, val|
37
- data["#{key.to_s}"] = "#{val.to_s}"
38
- end
39
-
40
- if request_i == 1
41
- hayabusa_session_id = data["cookie"]["HayabusaSession"]
42
- session_hash_obj_id = data["session_hash_id"]
43
- session_id = data["session_id"]
44
- end
45
-
46
- #puts "request-i: #{request_i}, data-request-count: #{data["request_count"]}, hash-id: #{data["session_hash_id"]}" if debug
47
-
48
- #Check 'HayabusaSession'-cookie.
49
- raise "No 'HayabusaSession'-cookie?" if !data["cookie"]["HayabusaSession"]
50
- raise "Expected 'HayabusaSession'-cookie to be '#{hayabusa_session_id}' but it wasnt: '#{data["cookie"]["HayabusaSession"]}' (#{data["cookie"]})." if hayabusa_session_id != data["cookie"]["HayabusaSession"]
51
-
52
- #Check session-hash-object-ID.
53
- raise "No 'session_hash_id' from request: '#{data}'." if data["session_hash_id"].to_s.strip.empty?
54
- raise "Expected session-hash-object-ID to be '#{session_hash_obj_id}' but it wasnt: '#{data["session_hash_id"]}'." if session_hash_obj_id != data["session_hash_id"] or !session_hash_obj_id
55
-
56
-
57
- #Check session-object-ID.
58
- raise "Expected session-ID to be '#{session_id}' but it wasnt: '#{data["session_id"]}' for request '#{request_i}'." if session_id != data["session_id"]
59
- raise "Expected request-count for session to be the same as on the client: '#{request_i}' but it wasnt: '#{data["request_count"]}'." if data["request_count"].to_i != request_i
60
- end
61
- end
62
- rescue => e
63
- errs << e
64
- end
65
- end
66
- end
67
-
68
- ts.each do |t|
69
- t.join
70
- end
71
-
72
- errs.each do |e|
73
- raise e
74
- end
75
- end
76
-
77
- it "two simultanious request should be handeled by the same process - one should proxy the request" do
78
- Knj.gem_require(:Http2, "http2")
79
- require "json"
80
-
81
- Http2.new(:host => "localhost") do |http1|
82
- Http2.new(:host => "localhost") do |http2|
83
- res1 = nil
84
- res2 = nil
85
-
86
- t1 = Thread.new do
87
- res1 = http1.get(:url => "hayabusa_fcgi_test/spec_sleeper.rhtml")
88
- end
89
-
90
- t2 = Thread.new do
91
- res2 = http2.get(:url => "hayabusa_fcgi_test/spec_sleeper.rhtml")
92
- end
93
-
94
- t1.join
95
- t2.join
96
-
97
- pid1 = res1.body.to_i
98
- pid2 = res2.body.to_i
99
-
100
- raise "Expected PIDs to be the same: '#{res1.body}', '#{res2.body}'." if pid1 != pid2 or pid1 == 0 or pid2 == 0
101
- end
102
- end
103
- end
104
- end
@@ -1,423 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Hayabusa" do
4
- require "rubygems"
5
- require "sqlite3" if RUBY_ENGINE != "jruby"
6
- require "json"
7
- require "RMagick"
8
-
9
- begin
10
- require "#{File.realpath(File.dirname(__FILE__))}/../../knjrbfw/lib/knjrbfw.rb"
11
- rescue LoadError
12
- require "knjrbfw"
13
- end
14
-
15
- require "#{File.realpath(File.dirname(__FILE__))}/../lib/hayabusa.rb"
16
-
17
- begin
18
- require "#{File.realpath(File.dirname(__FILE__))}/../../http2/lib/http2.rb"
19
- puts "Loaded custom version of Http2."
20
- rescue LoadError
21
- require "http2"
22
- puts "Loaded normal gem version of Http2."
23
- end
24
-
25
- db_path = "#{Knj::Os.tmpdir}/hayabusa_rspec.sqlite3"
26
- File.unlink(db_path) if File.exists?(db_path)
27
-
28
- db = Knj::Db.new(
29
- :type => "sqlite3",
30
- :path => db_path,
31
- :return_keys => "symbols"
32
- )
33
-
34
- $appserver = Hayabusa.new(
35
- :debug => false,
36
- :title => "SpecTest",
37
- :port => 1515,
38
- :doc_root => "#{File.dirname(__FILE__)}/../pages",
39
- :locales_gettext_funcs => true,
40
- :locale_default => "da_DK",
41
- :db => db,
42
- :threadding => {
43
- :priority => -3
44
- }
45
- )
46
-
47
- $appserver.config[:handlers] << {
48
- :regex => /^\/Kasper$/,
49
- :callback => proc{|data|
50
- data[:httpsession].page_path = nil
51
-
52
- eruby = data[:httpsession].eruby
53
- eruby.connect(:on_error) do |e|
54
- _hb.handle_error(e)
55
- end
56
-
57
- eruby.import("#{File.dirname(__FILE__)}/../pages/spec.rhtml")
58
- }
59
- }
60
-
61
- $appserver.vars[:test] = "kasper"
62
- $appserver.define_magic_var(:_testvar1, "Kasper")
63
- $appserver.define_magic_var(:_testvar2, "Johansen")
64
- $appserver.start
65
-
66
- raise "Expected thread-pool-priority to be '-3' but it wasnt: '#{$appserver.threadpool.args[:priority]}'." if $appserver.threadpool.args[:priority] != -3
67
-
68
- http = Http2.new(:host => "localhost", :port => 80, :encoding_gzip => false, :debug => false) rescue nil
69
-
70
- $testmodes = [{
71
- :name => :standalone,
72
- :path_pre => "",
73
- :http => Http2.new(:host => "localhost", :port => 1515, :debug => false)
74
- }]
75
-
76
- if http
77
- $testmodes += [{
78
- :name => :cgi,
79
- :path_pre => "hayabusa_cgi_test/",
80
- :http => http
81
- },{
82
- :name => :fcgi,
83
- :path_pre => "hayabusa_fcgi_test/",
84
- :http => http
85
- }]
86
- end
87
-
88
- it "should be able to get multiple pictures" do
89
- require "base64"
90
-
91
- # Symlink 'image.rhtml' first.
92
- img_from_path = "#{Knj.knjrbfw_path}/webscripts/image.rhtml"
93
- img_to_path = "#{File.realpath("#{File.dirname(__FILE__)}/../pages")}/image.rhtml"
94
-
95
- raise "Invalid from path: '#{img_from_path}'." unless File.exists?(img_from_path)
96
-
97
- File.unlink(img_to_path) if File.symlink?(img_to_path)
98
- File.symlink(img_from_path, img_to_path)
99
-
100
- last_tdata = nil
101
-
102
- begin
103
- $testmodes.each do |tdata|
104
- last_tdata = tdata
105
-
106
- 3.times do
107
- path = "#{File.dirname(__FILE__)}/../pages/testpic.jpeg"
108
-
109
- res = tdata[:http].get("#{tdata[:path_pre]}testpic.jpeg")
110
- res.body.bytesize.should eql(File.size(path))
111
-
112
- res.body.bytes.to_a.should eql(File.read(path).bytes.to_a)
113
-
114
- #puts "Getting forced image through #{tdata[:name]}"
115
- res = tdata[:http].get("#{tdata[:path_pre]}image.rhtml?force=true&path64=#{Base64.encode64("testpic.jpeg").to_s.strip}")
116
-
117
- #puts "Getting normal image through #{tdata[:name]}"
118
- res1 = tdata[:http].get("#{tdata[:path_pre]}image.rhtml?path64=#{Base64.encode64("image.png").to_s.strip}&rounded_corners=8&width=550")
119
- res1.contenttype.should eql("image/png")
120
-
121
- #puts "Getting exit-script through #{tdata[:name]}"
122
- res_exit = tdata[:http].get("#{tdata[:path_pre]}spec_exit.rhtml")
123
- res_exit.body.should eql("ExitOutput\n")
124
- res_exit.code.to_i.should eql(304)
125
-
126
- #puts "Getting normal image through #{tdata[:name]}"
127
- res2 = tdata[:http].get("#{tdata[:path_pre]}image.rhtml?path64=#{Base64.encode64("image.png").to_s.strip}&rounded_corners=8&width=550")
128
- res2.contenttype.should eql("image/png")
129
-
130
- res1.body.bytesize.should eql(res2.body.bytesize)
131
- end
132
- end
133
- rescue => e
134
- puts "Mode: #{last_tdata[:name]}" if last_tdata
135
- STDERR.puts e.inspect
136
- STDERR.puts e.backtrace
137
- raise e
138
- ensure
139
- File.unlink(img_to_path) if File.exists?(img_to_path)
140
- end
141
- end
142
-
143
- #it "should be able to handle custom urls" do
144
- # $testmodes.each do |tdata|
145
- # res = tdata[:http].get("#{tdata[:path_pre]}Kasper")
146
- # raise "Expected data to be 'Test' in mode '#{tdata[:name]}' but it wasnt: '#{res.body}'." if res.body != "Test"
147
- # end
148
- #end
149
-
150
- it "should be able to upload files" do
151
- $testmodes.each do |tdata|
152
- fpaths = {
153
- "fpath1" => "#{File.realpath(File.dirname(__FILE__))}/../pages/spec_thread_joins.rhtml",
154
- "fpath2" => "#{File.realpath(File.dirname(__FILE__))}/test_upload.xlsx"
155
- }
156
-
157
- res = tdata[:http].post_multipart(:url => "#{tdata[:path_pre]}spec_vars_post_fileupload.rhtml", :post => {
158
- "testfile1" => {
159
- :filename => "spec_thread_joins.rhtml",
160
- :fpath => fpaths["fpath1"]
161
- },
162
- "testfile2" => {
163
- :filename => "test_upload.xlsx",
164
- :fpath => fpaths["fpath2"]
165
- }
166
- })
167
-
168
- 1.upto(2) do |count|
169
- data = Marshal.load(res.body)
170
- raise "No data returned?" unless data
171
-
172
- if count != 2
173
- key = "testfile#{count}"
174
- raise "Not defined in returned data: '#{key}' in '#{data}'." unless data.key?(key)
175
- if data[key]["val"] != File.read(fpaths["fpath#{count}"])
176
- File.open("/tmp/hayabusa_spec_testfile#{count}_1", "w") do |fp|
177
- fp.puts("Class: #{data["testfile#{count}"].class.name}")
178
- fp.write(data["testfile#{count}"])
179
- end
180
-
181
- File.open("/tmp/hayabusa_spec_testfile#{count}_2", "w") do |fp|
182
- fp.write(File.read(fpaths["fpath#{count}"]))
183
- end
184
-
185
- raise "Expected uploaded data for mode '#{tdata[:name]}' to be the same but it wasnt:\n\"#{data["testfile#{count}"]}\"\n\n\"#{File.read(fpaths["fpath#{count}"])}\""
186
- end
187
- end
188
-
189
- raise "Expected 'testfile' class to be 'Hayabusa::Http_session::Post_multipart::File_upload' in mode '#{tdata[:name]}' but it wasnt: '#{data["testfile#{count}"]["class"]}'." if data["testfile#{count}"]["class"] != "Hayabusa::Http_session::Post_multipart::File_upload"
190
- end
191
- end
192
- end
193
-
194
- it "should be able to handle a GET-request." do
195
- $testmodes.each do |tdata|
196
- res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml")
197
- raise "Unexpected HTML: '#{res.body}'." if res.body.to_s != "Test"
198
-
199
- #Check that URL-decoding are being done.
200
- res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml?choice=check_get_parse&value=#{Knj::Web.urlenc("gfx/nopic.png")}")
201
- raise "Unexpected HTML: '#{res.body}'." if res.body.to_s != "gfx/nopic.png"
202
- end
203
- end
204
-
205
- it "should be able to handle a HEAD-request." do
206
- #Http2 doesnt support head?
207
- #res = $http.head("spec.rhtml")
208
- #raise "HEAD-request returned content - it shouldnt?" if res.body.to_s.length > 0
209
- end
210
-
211
- it "should be able to handle a POST-request." do
212
- $testmodes.each do |tdata|
213
- res = tdata[:http].post(:url => "#{tdata[:path_pre]}spec.rhtml", :post => {
214
- "postdata" => "Test post"
215
- })
216
- raise "POST-request did not return expected data: '#{res.body}' for '#{tdata[:name]}' data: '#{res.body}'." if res.body.to_s.strip != "Test post"
217
-
218
- res = tdata[:http].post(:url => "#{tdata[:path_pre]}spec.rhtml?choice=dopostconvert", :post => {
219
- "postdata" => "Test post",
220
- "array" => ["a", "b", "d"]
221
- })
222
- data = JSON.parse(res.body)
223
- raise "Expected posted data restored but it wasnt: '#{data}'." if data["array"]["0"] != "a" or data["array"]["1"] != "b" or data["array"]["2"] != "d"
224
- end
225
- end
226
-
227
- it "should be able to join the server so other tests can be made manually." do
228
- begin
229
- Timeout.timeout(1) do
230
- $appserver.join
231
- raise "Appserver didnt join."
232
- end
233
- rescue Timeout::Error
234
- #ignore.
235
- end
236
- end
237
-
238
- it "should be able to use the header-methods." do
239
- $testmodes.each do |tdata|
240
- res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml")
241
- raise "Normal header data could not be detected." if res.header("testheader") != "NormalHeader"
242
- raise "Raw header data could not be detected." if res.header("testraw") != "RawHeader"
243
- end
244
- end
245
-
246
- it "should be able to set and get multiple cookies at the same time." do
247
- $testmodes.each do |tdata|
248
- res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml?choice=test_cookie")
249
- raise res.body if res.body.to_s.length > 0
250
-
251
- res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml?choice=get_cookies")
252
- parsed = JSON.parse(res.body)
253
-
254
- raise "Unexpected value for 'TestCookie': '#{parsed["TestCookie"]}'." if parsed["TestCookie"] != "TestValue"
255
- raise "Unexpected value for 'TestCookie2': '#{parsed["TestCookie2"]}'." if parsed["TestCookie2"] != "TestValue2"
256
- raise "Unexpected value for 'TestCookie3': '#{parsed["TestCookie3"]}'." if parsed["TestCookie3"] != "TestValue 3 "
257
- end
258
- end
259
-
260
- it "should be able to run the rspec_threadded_content test correctly." do
261
- $testmodes.each do |tdata|
262
- res = tdata[:http].get("#{tdata[:path_pre]}spec_threadded_content.rhtml")
263
- raise "Expected body to be '12345678910' for mode '#{tdata[:name]}' but it wasnt: '#{res.body.to_s}'." if res.body.to_s != "12345678910"
264
- end
265
- end
266
-
267
- it "should be able to add a timeout." do
268
- $break_timeout = false
269
- timeout = $appserver.timeout(:time => 1) do
270
- $break_timeout = true
271
- end
272
-
273
- Timeout.timeout(2) do
274
- loop do
275
- break if $break_timeout
276
- sleep 0.1
277
- end
278
- end
279
- end
280
-
281
- it "should be able to stop a timeout." do
282
- $timeout_runned = false
283
- timeout = $appserver.timeout(:time => 1) do
284
- $timeout_runned = true
285
- end
286
-
287
- sleep 0.5
288
- timeout.stop
289
-
290
- begin
291
- Timeout.timeout(1.5) do
292
- loop do
293
- raise "The timeout ran even though stop was called?" if $timeout_runned
294
- sleep 0.1
295
- end
296
- end
297
- rescue Timeout::Error
298
- #the timeout didnt run - and it shouldnt so dont do anything.
299
- end
300
- end
301
-
302
- it "should be able to join threads tarted from _hb.thread." do
303
- $testmodes.each do |tdata|
304
- res = tdata[:http].get("#{tdata[:path_pre]}spec_thread_joins.rhtml")
305
- raise res.body if res.body.to_s != "12345"
306
- end
307
- end
308
-
309
- it "should be able to properly parse special characters in post-requests." do
310
- $testmodes.each do |tdata|
311
- res = tdata[:http].post(:url => "#{tdata[:path_pre]}spec_vars_post.rhtml", :post => {
312
- "test" => "123+456%789%20"
313
- })
314
- data = JSON.parse(res.body)
315
- raise res.body if data["test"] != "123+456%789%20"
316
- end
317
- end
318
-
319
- it "should be able to do logging" do
320
- class ::TestModels
321
- class Person < Knj::Datarow
322
-
323
- end
324
- end
325
-
326
- Knj::Db::Revision.new.init_db("db" => $appserver.db, "schema" => {
327
- "tables" => {
328
- "Person" => {
329
- "columns" => [
330
- {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
331
- {"name" => "name", "type" => "varchar"}
332
- ]
333
- }
334
- }
335
- })
336
-
337
- ob = Knj::Objects.new(
338
- :db => $appserver.db,
339
- :datarow => true,
340
- :require => false,
341
- :module => ::TestModels
342
- )
343
-
344
- person = ob.add(:Person, :name => "Kasper")
345
-
346
- $appserver.log("This is a test", person)
347
- logs = $appserver.ob.list(:Log, "object_lookup" => person).to_a
348
- raise "Expected count to be 1 but got: #{logs.length}" if logs.length != 1
349
-
350
- $appserver.logs_delete(person)
351
-
352
- logs = $appserver.ob.list(:Log, "object_lookup" => person).to_a
353
- raise "Expected count to be 0 but got: #{logs.length}" if logs.length != 0
354
- end
355
-
356
- it "should handle multi-threadding well" do
357
- ts = []
358
- es = []
359
-
360
- #Execute multiple threads to test FCGI-proxy and thread-safety.
361
- 1.upto(5) do
362
- $testmodes.each do |tdata|
363
- ts << Thread.new do
364
- begin
365
- res = tdata[:http].post(:url => "#{tdata[:path_pre]}spec_vars_post.rhtml", :post => {
366
- "test_special_chars" => "1%23+-456",
367
- "var" => {
368
- 0 => 1,
369
- 1 => 2,
370
- 3 => {
371
- "kasper" => 5,
372
- "arr" => ["a", "b", "c"]
373
- }
374
- }
375
- })
376
-
377
- begin
378
- data = JSON.parse(res.body)
379
- rescue
380
- raise "Could not parse JSON from result: '#{res.body}'."
381
- end
382
-
383
- begin
384
- raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5" or data["var"]["3"]["arr"]["0"] != "a" or data["var"]["3"]["arr"]["1"] != "b"
385
- rescue => e
386
- raise "Error when parsing result: '#{data}'."
387
- end
388
-
389
- raise "Expected 'test_special_chars' to be '1%23+-456' but it wasnt: '#{data["test_special_chars"]}'." if data["test_special_chars"] != "1%23+-456"
390
-
391
- res = tdata[:http].get("#{tdata[:path_pre]}spec_threadded_content.rhtml")
392
- raise "Expected body to be '12345678910' but it was: '#{res.body}'." if res.body != "12345678910"
393
-
394
- res = tdata[:http].get("#{tdata[:path_pre]}spec_vars_get.rhtml?var[]=1&var[]=2&var[]=3&var[3][kasper]=5")
395
- data = JSON.parse(res.body)
396
- raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5"
397
-
398
-
399
-
400
- res = tdata[:http].get("#{tdata[:path_pre]}spec_vars_header.rhtml")
401
- raise "Expected header 'testheader' to be 'TestValue' but it wasnt: '#{res.header("testheader")}'." if res.header("testheader") != "TestValue"
402
- rescue => e
403
- es << e
404
- puts e.inspect
405
- puts e.backtrace
406
- end
407
- end
408
- end
409
-
410
- ts.each do |t|
411
- t.join
412
- end
413
-
414
- es.each do |e|
415
- raise e
416
- end
417
- end
418
- end
419
-
420
- it "should be able to stop." do
421
- $appserver.stop
422
- end
423
- end