|
274 | 274 | expect(response.code).to eq(200) |
275 | 275 | end |
276 | 276 | end |
| 277 | + |
| 278 | + context "with reload" do |
| 279 | + let(:controller) { Pathname.new("#{__dir__}/test_app/app/controllers/reload_controller.rb") } |
| 280 | + |
| 281 | + before do |
| 282 | + @initial = controller.read |
| 283 | + end |
| 284 | + |
| 285 | + after do |
| 286 | + controller.write(@initial) |
| 287 | + end |
| 288 | + |
| 289 | + context "with new status" do |
| 290 | + before do |
| 291 | + controller.write <<~RUBY |
| 292 | + class ReloadController < RageController::API |
| 293 | + def verify |
| 294 | + head 207 |
| 295 | + end |
| 296 | + end |
| 297 | + RUBY |
| 298 | + end |
| 299 | + |
| 300 | + it "reloads the app" do |
| 301 | + response = HTTP.get("http://localhost:3000/reload/verify") |
| 302 | + expect(response.code).to eq(207) |
| 303 | + end |
| 304 | + end |
| 305 | + |
| 306 | + context "with async code" do |
| 307 | + before do |
| 308 | + controller.write <<~RUBY |
| 309 | + class ReloadController < RageController::API |
| 310 | + def verify |
| 311 | + f1 = Fiber.schedule { sleep 0.1 } |
| 312 | + f2 = Fiber.schedule { sleep 0.2 } |
| 313 | + Fiber.await([f1, f2]) |
| 314 | +
|
| 315 | + head 205 |
| 316 | + end |
| 317 | + end |
| 318 | + RUBY |
| 319 | + end |
| 320 | + |
| 321 | + it "reloads the app" do |
| 322 | + response = HTTP.get("http://localhost:3000/reload/verify") |
| 323 | + expect(response.code).to eq(205) |
| 324 | + end |
| 325 | + end |
| 326 | + |
| 327 | + context "with parallel requests" do |
| 328 | + before do |
| 329 | + controller.write <<~RUBY |
| 330 | + class ReloadController < RageController::API |
| 331 | + def verify |
| 332 | + sleep 0.1 |
| 333 | + head 208 |
| 334 | + end |
| 335 | + end |
| 336 | + RUBY |
| 337 | + end |
| 338 | + |
| 339 | + it "reloads the app" do |
| 340 | + requests = [ |
| 341 | + Thread.new { HTTP.get("http://localhost:3000/reload/verify") }, |
| 342 | + Thread.new { HTTP.get("http://localhost:3000/reload/verify") } |
| 343 | + ] |
| 344 | + |
| 345 | + requests.each(&:join) |
| 346 | + responses = requests.map(&:value) |
| 347 | + |
| 348 | + expect(responses.map(&:code).uniq).to eq([208]) |
| 349 | + end |
| 350 | + end |
| 351 | + end |
277 | 352 | end |
0 commit comments