polyphony 0.23 → 0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile.lock +4 -10
  4. data/README.md +0 -4
  5. data/TODO.md +5 -56
  6. data/docs/README.md +4 -7
  7. data/examples/core/{channel_echo.rb → xx-channels.rb} +0 -0
  8. data/examples/core/{defer.rb → xx-deferring-an-operation.rb} +0 -0
  9. data/examples/core/{genserver.rb → xx-erlang-style-genserver.rb} +2 -2
  10. data/examples/core/{fork.rb → xx-forking.rb} +2 -0
  11. data/examples/core/xx-move_on.rb +23 -0
  12. data/examples/core/{pulse.rb → xx-recurrent-timer.rb} +3 -2
  13. data/examples/core/{resource_cancel.rb → xx-resource_cancel.rb} +1 -2
  14. data/examples/core/{resource_delegate.rb → xx-resource_delegate.rb} +0 -0
  15. data/examples/core/{wait_for_signal.rb → xx-signals.rb} +0 -0
  16. data/examples/core/{sleep.rb → xx-sleeping.rb} +0 -0
  17. data/examples/core/{spin_error_backtrace.rb → xx-spin_error_backtrace.rb} +5 -2
  18. data/examples/core/{supervisor.rb → xx-supervisors.rb} +0 -0
  19. data/examples/core/{thread_cancel.rb → xx-thread_cancel.rb} +0 -0
  20. data/examples/core/{thread_pool.rb → xx-thread_pool.rb} +0 -0
  21. data/examples/core/{throttle.rb → xx-throttling.rb} +0 -0
  22. data/examples/core/{timeout.rb → xx-timeout.rb} +0 -0
  23. data/examples/core/{lock.rb → xx-using-a-mutex.rb} +0 -0
  24. data/examples/io/{backticks.rb → xx-backticks.rb} +0 -0
  25. data/examples/io/{echo_client.rb → xx-echo_client.rb} +0 -1
  26. data/examples/io/{echo_client_from_stdin.rb → xx-echo_client_from_stdin.rb} +0 -1
  27. data/examples/io/{echo_pipe.rb → xx-echo_pipe.rb} +0 -0
  28. data/examples/io/{echo_server.rb → xx-echo_server.rb} +0 -0
  29. data/examples/io/{echo_server_with_timeout.rb → xx-echo_server_with_timeout.rb} +0 -0
  30. data/examples/io/{echo_stdin.rb → xx-echo_stdin.rb} +0 -0
  31. data/examples/io/xx-httparty.rb +13 -0
  32. data/examples/io/{irb.rb → xx-irb.rb} +0 -0
  33. data/examples/io/{net-http.rb → xx-net-http.rb} +0 -0
  34. data/examples/io/{open.rb → xx-open.rb} +0 -1
  35. data/examples/io/{system.rb → xx-system.rb} +0 -0
  36. data/examples/io/{tcpserver.rb → xx-tcpserver.rb} +0 -0
  37. data/examples/io/{tcpsocket.rb → xx-tcpsocket.rb} +0 -1
  38. data/examples/{fs/read.rb → performance/fs_read.rb} +0 -0
  39. data/examples/{core → performance}/mem-usage.rb +1 -0
  40. data/examples/performance/multi_snooze.rb +2 -0
  41. data/examples/performance/snooze.rb +2 -0
  42. data/examples/performance/thread-vs-fiber/polyphony_server.rb +5 -3
  43. data/examples/performance/thread-vs-fiber/threaded_server.rb +1 -1
  44. data/examples/{io/httparty_multi.rb → performance/thread-vs-fiber/xx-httparty_multi.rb} +16 -13
  45. data/examples/{io/httparty_threaded.rb → performance/thread-vs-fiber/xx-httparty_threaded.rb} +2 -2
  46. data/examples/performance/thread.rb +27 -0
  47. data/examples/{core → performance}/thread_pool_perf.rb +0 -0
  48. data/ext/gyro/extconf.rb +1 -0
  49. data/lib/polyphony/extensions/core.rb +0 -5
  50. data/lib/polyphony/version.rb +1 -1
  51. data/polyphony.gemspec +3 -9
  52. metadata +59 -167
  53. data/bin/poly +0 -11
  54. data/examples/core/cancel.rb +0 -13
  55. data/examples/core/enumerator.rb +0 -15
  56. data/examples/core/error_bubbling.rb +0 -35
  57. data/examples/core/fiber_error.rb +0 -9
  58. data/examples/core/fiber_error_with_backtrace.rb +0 -73
  59. data/examples/core/move_on.rb +0 -11
  60. data/examples/core/move_on_twice.rb +0 -16
  61. data/examples/core/move_on_with_ensure.rb +0 -13
  62. data/examples/core/move_on_with_value.rb +0 -14
  63. data/examples/core/multiple_spin.rb +0 -18
  64. data/examples/core/nested_cancel.rb +0 -40
  65. data/examples/core/nested_multiple_spin.rb +0 -20
  66. data/examples/core/nested_spin.rb +0 -19
  67. data/examples/core/pingpong.rb +0 -21
  68. data/examples/core/resource.rb +0 -30
  69. data/examples/core/sleep_spin.rb +0 -21
  70. data/examples/core/snooze.rb +0 -32
  71. data/examples/core/spin_error.rb +0 -17
  72. data/examples/core/spin_uncaught_error.rb +0 -16
  73. data/examples/core/supervisor_with_cancel_scope.rb +0 -23
  74. data/examples/core/supervisor_with_error.rb +0 -24
  75. data/examples/core/supervisor_with_manual_move_on.rb +0 -23
  76. data/examples/core/suspend.rb +0 -13
  77. data/examples/core/thread.rb +0 -27
  78. data/examples/http/config.ru +0 -7
  79. data/examples/http/cuba.ru +0 -22
  80. data/examples/http/happy_eyeballs.rb +0 -37
  81. data/examples/http/http2_raw.rb +0 -135
  82. data/examples/http/http_client.rb +0 -28
  83. data/examples/http/http_get.rb +0 -33
  84. data/examples/http/http_parse_experiment.rb +0 -123
  85. data/examples/http/http_proxy.rb +0 -83
  86. data/examples/http/http_server.js +0 -24
  87. data/examples/http/http_server.rb +0 -28
  88. data/examples/http/http_server_forked.rb +0 -29
  89. data/examples/http/http_server_graceful.rb +0 -27
  90. data/examples/http/http_server_simple.rb +0 -11
  91. data/examples/http/http_server_throttled.rb +0 -15
  92. data/examples/http/http_ws_server.rb +0 -37
  93. data/examples/http/https_raw_client.rb +0 -12
  94. data/examples/http/https_server.rb +0 -22
  95. data/examples/http/https_wss_server.rb +0 -39
  96. data/examples/http/rack_server.rb +0 -12
  97. data/examples/http/rack_server_https.rb +0 -19
  98. data/examples/http/rack_server_https_forked.rb +0 -27
  99. data/examples/http/websocket_secure_server.rb +0 -27
  100. data/examples/http/websocket_server.rb +0 -24
  101. data/examples/http/ws_page.html +0 -34
  102. data/examples/http/wss_page.html +0 -34
  103. data/examples/io/cat.rb +0 -12
  104. data/examples/io/httparty.rb +0 -10
  105. data/examples/io/io_read.rb +0 -9
  106. data/lib/ev_ext.bundle +0 -0
  107. data/lib/polyphony/http.rb +0 -16
  108. data/lib/polyphony/http/client/agent.rb +0 -131
  109. data/lib/polyphony/http/client/http1.rb +0 -129
  110. data/lib/polyphony/http/client/http2.rb +0 -180
  111. data/lib/polyphony/http/client/response.rb +0 -32
  112. data/lib/polyphony/http/client/site_connection_manager.rb +0 -109
  113. data/lib/polyphony/http/server.rb +0 -49
  114. data/lib/polyphony/http/server/http1.rb +0 -268
  115. data/lib/polyphony/http/server/http2.rb +0 -78
  116. data/lib/polyphony/http/server/http2_stream.rb +0 -136
  117. data/lib/polyphony/http/server/rack.rb +0 -64
  118. data/lib/polyphony/http/server/request.rb +0 -118
  119. data/lib/polyphony/websocket.rb +0 -59
  120. data/test/test_http_server.rb +0 -313
@@ -1,313 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
- require 'polyphony/http'
5
-
6
- class String
7
- def http_lines
8
- gsub "\n", "\r\n"
9
- end
10
- end
11
-
12
- class IO
13
- # Creates two mockup sockets for simulating server-client communication
14
- def self.server_client_mockup
15
- server_in, client_out = IO.pipe
16
- client_in, server_out = IO.pipe
17
-
18
- server_connection = mockup_connection(server_in, server_out, client_out)
19
- client_connection = mockup_connection(client_in, client_out, server_out)
20
-
21
- [server_connection, client_connection]
22
- end
23
-
24
- def self.mockup_connection(input, output, output2)
25
- eg(
26
- :read => ->(*args) { input.read(*args) },
27
- :readpartial => ->(*args) { input.readpartial(*args) },
28
- :<< => ->(*args) { output.write(*args) },
29
- :write => ->(*args) { output.write(*args) },
30
- :close => -> { output.close },
31
- :eof? => -> { output2.closed? }
32
- )
33
- end
34
- end
35
-
36
- class HTTP1ServerTest < MiniTest::Test
37
- def teardown
38
- @server&.interrupt if @server&.alive?
39
- snooze
40
- super
41
- end
42
-
43
- def spin_server(opts = {}, &handler)
44
- server_connection, client_connection = IO.server_client_mockup
45
- coproc = spin do
46
- Polyphony::HTTP::Server.client_loop(server_connection, opts, &handler)
47
- end
48
- [coproc, client_connection, server_connection]
49
- end
50
-
51
- def test_that_server_uses_content_length_in_http_1_0
52
- @server, connection = spin_server do |req|
53
- req.respond('Hello, world!', {})
54
- end
55
-
56
- # using HTTP 1.0, server should close connection after responding
57
- connection << "GET / HTTP/1.0\r\n\r\n"
58
-
59
- response = connection.readpartial(8192)
60
- expected = <<~HTTP.chomp.http_lines
61
- HTTP/1.0 200
62
- Content-Length: 13
63
-
64
- Hello, world!
65
- HTTP
66
- assert_equal(expected, response)
67
- end
68
-
69
- def test_that_server_uses_chunked_encoding_in_http_1_1
70
- @server, connection = spin_server do |req|
71
- req.respond('Hello, world!')
72
- end
73
-
74
- # using HTTP 1.0, server should close connection after responding
75
- connection << "GET / HTTP/1.1\r\n\r\n"
76
-
77
- response = connection.readpartial(8192)
78
- expected = <<~HTTP.http_lines
79
- HTTP/1.1 200
80
- Transfer-Encoding: chunked
81
-
82
- d
83
- Hello, world!
84
- 0
85
-
86
- HTTP
87
- assert_equal(expected, response)
88
- end
89
-
90
- def test_that_server_maintains_connection_when_using_keep_alives
91
- puts 'test_that_server_maintains_connection_when_using_keep_alives'
92
- @server, connection = spin_server do |req|
93
- req.respond('Hi', {})
94
- end
95
-
96
- connection << "GET / HTTP/1.0\r\nConnection: keep-alive\r\n\r\n"
97
- response = connection.readpartial(8192)
98
- assert !connection.eof?
99
- assert_equal("HTTP/1.0 200\r\nContent-Length: 2\r\n\r\nHi", response)
100
-
101
- connection << "GET / HTTP/1.1\r\n\r\n"
102
- response = connection.readpartial(8192)
103
- assert !connection.eof?
104
- expected = <<~HTTP.http_lines
105
- HTTP/1.1 200
106
- Transfer-Encoding: chunked
107
-
108
- 2
109
- Hi
110
- 0
111
-
112
- HTTP
113
- assert_equal(expected, response)
114
-
115
- connection << "GET / HTTP/1.0\r\n\r\n"
116
- response = connection.readpartial(8192)
117
- assert connection.eof?
118
- assert_equal("HTTP/1.0 200\r\nContent-Length: 2\r\n\r\nHi", response)
119
- end
120
-
121
- def test_pipelining_client
122
- @server, connection = spin_server do |req|
123
- if req.headers['Foo'] == 'bar'
124
- req.respond('Hello, foobar!', {})
125
- else
126
- req.respond('Hello, world!', {})
127
- end
128
- end
129
-
130
- connection << "GET / HTTP/1.1\r\n\r\nGET / HTTP/1.1\r\nFoo: bar\r\n\r\n"
131
- response = connection.readpartial(8192)
132
-
133
- expected = <<~HTTP.http_lines
134
- HTTP/1.1 200
135
- Transfer-Encoding: chunked
136
-
137
- d
138
- Hello, world!
139
- 0
140
-
141
- HTTP/1.1 200
142
- Transfer-Encoding: chunked
143
-
144
- e
145
- Hello, foobar!
146
- 0
147
-
148
- HTTP
149
- assert_equal(expected, response)
150
- end
151
-
152
- def test_body_chunks
153
- chunks = []
154
- request = nil
155
- @server, connection = spin_server do |req|
156
- request = req
157
- req.send_headers
158
- req.each_chunk do |c|
159
- chunks << c
160
- req << c.upcase
161
- end
162
- req.finish
163
- end
164
-
165
- connection << <<~HTTP.http_lines
166
- POST / HTTP/1.1
167
- Transfer-Encoding: chunked
168
-
169
- 6
170
- foobar
171
- HTTP
172
- 2.times { snooze }
173
- assert request
174
- assert_equal %w[foobar], chunks
175
- assert !request.complete?
176
-
177
- connection << "6\r\nbazbud\r\n"
178
- snooze
179
- assert_equal %w[foobar bazbud], chunks
180
- assert !request.complete?
181
-
182
- connection << "0\r\n\r\n"
183
- snooze
184
- assert_equal %w[foobar bazbud], chunks
185
- assert request.complete?
186
-
187
- 2.times { snooze }
188
-
189
- response = connection.readpartial(8192)
190
-
191
- expected = <<~HTTP.http_lines
192
- HTTP/1.1 200
193
- Transfer-Encoding: chunked
194
-
195
- 6
196
- FOOBAR
197
- 6
198
- BAZBUD
199
- 0
200
-
201
- HTTP
202
- assert_equal(expected, response)
203
- end
204
-
205
- def test_upgrade
206
- done = nil
207
-
208
- opts = {
209
- upgrade: {
210
- echo: lambda do |conn, _headers|
211
- conn << <<~HTTP.http_lines
212
- HTTP/1.1 101 Switching Protocols
213
- Upgrade: echo
214
- Connection: Upgrade
215
-
216
- HTTP
217
-
218
- while (data = conn.readpartial(8192))
219
- conn << data
220
- snooze
221
- end
222
- done = true
223
- end
224
- }
225
- }
226
-
227
- @server, connection = spin_server(opts) do |req|
228
- req.respond('Hi')
229
- end
230
-
231
- connection << "GET / HTTP/1.1\r\n\r\n"
232
- response = connection.readpartial(8192)
233
- assert !connection.eof?
234
- expected = <<~HTTP.http_lines
235
- HTTP/1.1 200
236
- Transfer-Encoding: chunked
237
-
238
- 2
239
- Hi
240
- 0
241
-
242
- HTTP
243
- assert_equal(expected, response)
244
-
245
- connection << <<~HTTP.http_lines
246
- GET / HTTP/1.1
247
- Upgrade: echo
248
- Connection: upgrade
249
-
250
- HTTP
251
-
252
- snooze
253
- response = connection.readpartial(8192)
254
- assert !connection.eof?
255
- expected = <<~HTTP.http_lines
256
- HTTP/1.1 101 Switching Protocols
257
- Upgrade: echo
258
- Connection: Upgrade
259
-
260
- HTTP
261
- assert_equal(expected, response)
262
-
263
- assert !done
264
-
265
- connection << 'foo'
266
- assert_equal 'foo', connection.readpartial(8192)
267
-
268
- connection << 'bar'
269
- assert_equal 'bar', connection.readpartial(8192)
270
-
271
- connection.close
272
- assert !done
273
- snooze
274
- assert done
275
- end
276
-
277
- def test_big_download
278
- chunk_size = 100_000
279
- chunk_count = 10
280
- chunk = '*' * chunk_size
281
- @server, connection = spin_server do |req|
282
- req.send_headers
283
- chunk_count.times do
284
- req << chunk
285
- snooze
286
- end
287
- req.finish
288
- req.adapter.close
289
- end
290
-
291
- response = +''
292
- count = 0
293
-
294
- connection << "GET / HTTP/1.1\r\n\r\n"
295
- while (data = connection.readpartial(chunk_size * 2))
296
- response << data
297
- count += 1
298
- snooze
299
- end
300
-
301
- chunks = "#{chunk_size.to_s(16)}\n#{'*' * chunk_size}\n" * chunk_count
302
- expected = <<~HTTP.http_lines
303
- HTTP/1.1 200
304
- Transfer-Encoding: chunked
305
-
306
- #{chunks}0
307
-
308
- HTTP
309
-
310
- assert_equal expected, response
311
- assert_equal chunk_count * 2 + 1, count
312
- end
313
- end