Class: TestSendFile
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestSendFile
show all
- Defined in:
- lib/ext/eventmachine-0.12.10/tests/test_send_file.rb
Defined Under Namespace
Modules: BadFileTestModule, ChunkStreamTestModule, StreamTestModule, TestClient, TestModule
Constant Summary
collapse
- TestHost =
"0.0.0.0"
- TestPort =
9055
- TestFilename =
"./xxxxxx"
Instance Method Summary
collapse
Instance Method Details
#setup ⇒ Object
59
60
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 59
def setup
end
|
#teardown ⇒ Object
62
63
64
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 62
def teardown
File.unlink( TestFilename ) if File.exist?( TestFilename )
end
|
#test_send_file ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 66
def test_send_file
File.open( TestFilename, "w" ) {|f|
f << ("A" * 5000)
}
data = ''
EM.run {
EM.start_server TestHost, TestPort, TestModule
EM.add_timer(2) {EM.stop}
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
assert_equal( "A" * 5000, data )
File.unlink TestFilename
end
|
#test_send_large_file ⇒ Object
EventMachine::Connection#send_file_data has a strict upper limit on the filesize it will work with.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 87
def test_send_large_file
File.open( TestFilename, "w" ) {|f|
f << ("A" * 1000000)
}
data = ''
ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
assert_raises( ex_class ) {
EM.run {
EM.start_server TestHost, TestPort, TestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
}
File.unlink TestFilename
end
|
#test_stream_bad_file ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 174
def test_stream_bad_file
data = ''
EM.run {
EM.start_server TestHost, TestPort, BadFileTestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
assert_equal( "file not found", data )
end
|
#test_stream_chunked_file_data ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 145
def test_stream_chunked_file_data
File.open( TestFilename, "w" ) {|f|
f << ("A" * 1000)
}
data = ''
EM.run {
EM.start_server TestHost, TestPort, ChunkStreamTestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
assert_equal( "3e8\r\n#{"A" * 1000}\r\n0\r\n\r\n", data )
File.unlink TestFilename
end
|
#test_stream_file_data ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 125
def test_stream_file_data
File.open( TestFilename, "w" ) {|f|
f << ("A" * 1000)
}
data = ''
EM.run {
EM.start_server TestHost, TestPort, StreamTestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
assert_equal( "A" * 1000, data )
File.unlink TestFilename
end
|
#test_stream_large_chunked_file_data ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 212
def test_stream_large_chunked_file_data
begin
require 'fastfilereaderext'
rescue LoadError
return
end
File.open( TestFilename, "w" ) {|f|
f << ("A" * 100000)
}
data = ''
EM.run {
EM.start_server TestHost, TestPort, ChunkStreamTestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
expected = [
"4000\r\n#{"A" * 16384}\r\n" * 6,
"6a0\r\n#{"A" * 0x6a0}\r\n",
"0\r\n\r\n"
].join
assert_equal( expected, data )
File.unlink TestFilename
end
|
#test_stream_large_file_data ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/ext/eventmachine-0.12.10/tests/test_send_file.rb', line 187
def test_stream_large_file_data
begin
require 'fastfilereaderext'
rescue LoadError
return
end
File.open( TestFilename, "w" ) {|f|
f << ("A" * 10000)
}
data = ''
EM.run {
EM.start_server TestHost, TestPort, StreamTestModule
EM.add_timer(2) {EM.stop} EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
}
assert_equal( "A" * 10000, data )
File.unlink TestFilename
end
|