Giter Site home page Giter Site logo

raggi / async_sinatra Goto Github PK

View Code? Open in Web Editor NEW
434.0 9.0 42.0 73 KB

A plugin for Sinatra to provide a DSL extension for using Thin for asynchronous responses

Home Page: http://rubyforge.org/libraggi/async_sinatra

Ruby 100.00%
ruby async rack sinatra eventmachine thin

async_sinatra's Introduction

async_sinatra

github.com/raggi/async_sinatra

DESCRIPTION:

A Sinatra plugin to provide convenience whilst performing asynchronous responses inside of the Sinatra framework running under async webservers.

To properly utilise this package, some knowledge of EventMachine and/or asynchronous patterns is recommended.

Currently, supporting servers include:

  • Thin

  • Rainbows

  • Zbatery

SYNOPSIS:

A quick example:

require 'sinatra/async'

class AsyncTest < Sinatra::Base
  register Sinatra::Async

  aget '/' do
    body "hello async"
  end

  aget '/delay/:n' do |n|
    EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
  end

end

See Sinatra::Async for more details.

REQUIREMENTS:

  • Sinatra (>= 1.3.2)

  • An async webserver

INSTALL:

  • gem install async_sinatra

LICENSE:

(The MIT License)

Copyright © 2009 James Tucker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

async_sinatra's People

Contributors

boxofrad avatar dalehamel avatar emschwar avatar gruis avatar joeljackson avatar pje avatar raggi avatar soffes avatar tmm1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async_sinatra's Issues

"Cannot determine sinatra application" error using rspec

This gist explains it:

https://gist.github.com/3464182/6847ae1affb6dc5c2be960dbd5936d31107407f7

 Failures:
 
 1) MyApp can access the base route.
     Failure/Error: aget '/'
     RuntimeError:
       Cannot determine sinatra application from #>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :xss_mode=>:block, :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :xss_mode=>:block, :frame_options=>:sameorigin, :except=>[:session_hijacking, :remote_token]}>, @level=1>, @logger=nil>>>
     # ./app_spec.rb:20:in `block (2 levels) in '
 
Finished in 0.05393 seconds
1 example, 1 failure

Sinatra version is at 1.3.3
async_sinatra (1.0.0)
rspec-core (2.12.2)

test.rb does not run with EventMachine 0.12.10

test_async.rb fails with this error with EventMachine 0.12.10. I believe the fix is to change "EM.tick_loop" to "EM.next_tick" in lib/sinatra/async/test.rb:61.

test_em_halt(TestSinatraAsync):
NoMethodError: undefined method tick_loop' for EventMachine:Module /opt/local/lib/ruby/gems/1.8/gems/async_sinatra-0.2.1/lib/sinatra/async/test.rb:61 /opt/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:incall'
/opt/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in run_machine' /opt/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:inrun'
/opt/local/lib/ruby/gems/1.8/gems/async_sinatra-0.2.1/lib/sinatra/async/test.rb:59:in `em_async_continue'

Compatibility with Capybara integration specs

I have an async_sinatra app mounted within the routes of a Rails app. When running capybara selenium or poltergeist specs it hangs on any async actions.

Has anyone figured out a way around this?

Thank you!

cannot run with rainbows, puma, zbatery

I've tried the example code and I could only make it run with thin.
Whenever I try to execute it with rainbows, puma or zbatery This is the output I get:

I, [2013-09-27T14:00:11.622946 #22958]  INFO -- : listening on addr=0.0.0.0:8080 fd=9
I, [2013-09-27T14:00:11.623052 #22958]  INFO -- : worker=0 spawning...
I, [2013-09-27T14:00:11.623893 #22958]  INFO -- : master process ready
I, [2013-09-27T14:00:11.625906 #22960]  INFO -- : worker=0 spawned pid=22960
I, [2013-09-27T14:00:11.626466 #22960]  INFO -- : Refreshing Gem list
I, [2013-09-27T14:00:11.686086 #22960]  INFO -- : Rainbows! Base worker_connections=1
I, [2013-09-27T14:00:11.686161 #22960]  INFO -- : worker=0 ready
NameError - uninitialized constant Sinatra::Async::Helpers::EM:
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:132:in `native_async_schedule'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:124:in `async_schedule'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:142:in `async_runner'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:68:in `block in aroute'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1540:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1540:in `block in compile!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `[]'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `block (3 levels) in route!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:966:in `route_eval'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `block (2 levels) in route!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:987:in `block in process_route'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:985:in `catch'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:985:in `process_route'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:948:in `block in route!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:947:in `each'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:947:in `route!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1059:in `block in dispatch!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `block in invoke'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `catch'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `invoke'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1056:in `dispatch!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:882:in `block in call!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `block in invoke'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `catch'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `invoke'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:882:in `call!'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:870:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/showexceptions.rb:21:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:175:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1949:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1449:in `block in call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1726:in `synchronize'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1449:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:49:in `_call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:212:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/max_body.rb:66:in `block in call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/max_body.rb:59:in `catch'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/max_body.rb:59:in `call'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/process_client.rb:44:in `process_loop'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/base.rb:32:in `process_client'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:632:in `worker_loop'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/http_server.rb:45:in `worker_loop'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/lib/rainbows/http_server.rb:61:in `spawn_missing_workers'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:142:in `start'
    /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.5.0/bin/rainbows:127:in `<top (required)>'
    /usr/local/rvm/gems/ruby-2.0.0-p247/bin/rainbows:23:in `load'
    /usr/local/rvm/gems/ruby-2.0.0-p247/bin/rainbows:23:in `<main>'
    /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
    /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
127.0.0.1 - - [27/Sep/2013 14:00:26] "GET / HTTP/1.1" 500 174534 0.0598

Unnecessary rack 1.2.1 dependency

In the 0.5.0 build, there's a rack 1.2.1 dependency which isn't necessary because of the Sinatra => 1.0.x dependency. This will break things if running async_sinatra in a Rails 2.3.x environment. Its pretty easy to just remove rack from the dependencies and let whatever version of Sinatra you're using deal with that. Perhaps you meant to add this only as a development dependency for Rack::Test?

An async response within a websocket handler

I see that you've been looking for a maintainer for like two years, so you might not be answering these anymore. But I thought I might ask. My question is originally posted on Stack Overflow here.

Basically, I need to communicate with another server that only uses websockets, which means I need to wait for its messages, then wait for it to close, and then send the HTTP response to the client, based on that information. I'm using async_sinatra for this, but when I call the body method within the websocket logic, nothing happens.

problem with rainbows

with rainbows i get this error:

NoMethodError: undefined method each' for "hello async":String /Users/Francesco/.rvm/gems/ruby-1.9.2-p0/gems/rainbows-2.0.1/lib/rainbows/response/body.rb:118:inwrite_body_each'
/Users/Francesco/.rvm/gems/ruby-1.9.2-p0/gems/rainbows-2.0.1/lib/rainbows/event_machine.rb:149:in em_write_response' /Users/Francesco/.rvm/gems/ruby-1.9.2-p0/gems/async_sinatra-0.3.0/lib/sinatra/async.rb:80:in[]'
/Users/Francesco/.rvm/gems/ruby-1.9.2-p0/gems/async_sinatra-0.3.0/lib/sinatra/async.rb:80:in `body'

with this configuration:

worker_processes 1

Rainbows! do
use :EventMachine
worker_connections 100
end

body called twice

Hi, I'm having a very strange problem with async_sinatra.
Apparently the 'puts request.body.string' is called twice when receives a POST request.

https://gist.github.com/874281

If I use the normal post method from sinatra I have the output I expect, if I use async this is what I see:

{"subdomain":"test","given_name":"Wieland","nickname":"nwieland","location":null,"url":"http://nofeed.org","designs":[]}
{"subdomain":"test","given_name":"Wieland","nickname":"nwieland","location":null,"url":"http://nofeed.org","designs":[]}

Am I doing something wrong ? Or is it async_sinatra ?

testing async sinatra app in rails 3

full codes: https://gist.github.com/867967

i tried modify lib/sinatra/async/test.rb:81 from options to settings, but it failed with:
NoMethodError:
undefined method async_schedules' for AsyncTest:Class # /home/ayaya/.rvm/gems/ruby-1.9.2-p180/gems/async_sinatra-0.5.0/lib/sinatra/async/test.rb:81:inasync_continue'
# /home/ayaya/.rvm/gems/ruby-1.9.2-p180/gems/async_sinatra-0.5.0/lib/sinatra/async/test.rb:59:in aget' # ./spec/metals/async_test_spec.rb:14:inblock (3 levels) in <top (required)>'

How to test async sinatra apps ?

Hi,

I just wonder if you could give some details related to testing Sinatra apps using async_sinatra. I just rolled my own (simple) solution at http://github.com/crohr/rack-async2sync which is a rack middleware that exposes the asynchronous requests as if they were synchronous (by catching the throw(:async) call). This allows using Rack::Test transparently however I'm not sure whether this is the correct approach or not.

Thanks,
Cyril

Cannot test async_sinatra with cucumber

-> % bundle exec cucumber
Feature: Herp

  Scenario: Derp          # features/test.feature:3
    Given I am a bug      # features/step_definitions/derp_steps.rb:1
    When I get "/"        # features/step_definitions/derp_steps.rb:4
      undefined method `options' for #<Rack::Head:0x7f786dfbdf50> (NoMethodError)
      ./features/step_definitions/derp_steps.rb:5:in `/^I get "([^"]*)"$/'
      features/test.feature:5:in `When I get "/"'
    Then I should asplode # features/step_definitions/derp_steps.rb:9

Failing Scenarios:
cucumber features/test.feature:3 # Scenario: Derp

1 scenario (1 failed)
3 steps (1 failed, 1 skipped, 1 passed)
0m0.007s
-> %  

I've got a full reproduction test case in this GitHub repository

route parameters not in params?

Gist with data: https://gist.github.com/882330

Code:

  aget "/api/v1/inputs/:id" do |*args|
    # get a particular input
    @logger.info args
    @logger.info params
  end # aget "/api/v1/inputs/:id"

In Sinatra 1.2, async_sinatra 0.5.0, and rack 1.2.1, the above prints 'args' with the :id value, but params misses the value. In Sinatra 1.1 same effect. Sinatra 1.0 it works. (The changes were I would gem uninstall sinatra -v 1.2, gem install sinatra -v 1.1, etc).

If I replace 'aget' with 'get', it works correctly in Sinatra 1.2.

Bug?

Filestreamer compatibility?

I noticed that EM::FileStreamer requires a connection to be passed to it as an initialization argument. Is it possible to get a handle to the current connection in order to pass it to filestreamer?

Async sinatra + Thin is blocking my other requests

When I am issuing multiple request to a Sinatra instance with Async Sinatra, it seems to only handle on request at a time and blocking the others. Am I doing something wrong, or is this a bug with some particular version of thin/rack/sinatra?
I think this example should take 5-6 secs and not 25.

Example:

require 'rubygems'
require 'sinatra/async'

class MyApp < Sinatra::Base
  register Sinatra::Async

  set :server, 'thin'

  aget '/' do
    EM.add_timer(5) { body {"delayed for 5 seconds" } }
  end

end

MyApp.run!

And ab gives me:
ab -n 5 http://127.0.0.1:4567/
Time taken for tests: 25.230 seconds

after filter runs before method

Title says it all:

require 'sinatra/async'

class TestServer < Sinatra::Base
  register Sinatra::Async

  before do
    puts 'before'
  end

  after do
    puts 'after'
  end

  aget '/1' do
    puts 'aget /1'
    body ''
  end

  get '/2' do
    puts 'get /2'
    ''
  end

end

TestServer.run!

http://localhost:4567/1 prints:

before
after
aget /1

http://localhost:4567/2 prints:

before
get /2
after

When there is an exception within a route's block an error occurs while trying to handle it

If an exception appears within the code of a route's block Im not able to see info about it because (I believe) another exception occurs while sinatra-async tries to send the exception to be displayed, here is the full traceback:

== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
Stopping ...
== Sinatra has ended his set (crowd applauds)
/Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call': undefined method `join' for #<String:0x007fbab19fc6a8> (NoMethodError)
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:169:in `rescue in async_handle_exception'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:165:in `async_handle_exception'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:155:in `async_catch_execute'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/async_sinatra-1.1.0/lib/sinatra/async.rb:124:in `block in async_schedule'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:968:in `call'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:968:in `block in run_deferred_callbacks'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:965:in `times'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:965:in `run_deferred_callbacks'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/rack-1.6.0/lib/rack/handler/thin.rb:19:in `run'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/sinatra-1.4.5/lib/sinatra/base.rb:1497:in `start_server'
    from /Users/messutiEdd/.rvm/gems/ruby-1.9.3-p362/gems/sinatra-1.4.5/lib/sinatra/base.rb:1435:in `run!'
    from app.rb:19:in `<class:AsyncTest>'
    from app.rb:3:in `<main>'

I'm able to reproduce this with the basic example app from the readme:

require 'sinatra/async'

class AsyncTest < Sinatra::Base
  register Sinatra::Async

  aget '/' do
    body "hello async"
  end

  aget '/error' do
    throw "boom"
    body "hello async"
  end

  aget '/delay/:n' do |n|
    EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
  end

  run!
end

AsyncTest.new

async_sinatra 0.3.0 gem fails tests

Trying to run the test provided in the async_sinatra 0.3.0 I get the following error:

@@@
rake aborted!
can't convert nil into String
/var/tmp/portage/dev-ruby/async_sinatra-0.3.0/work/all/async_sinatra-0.3.0/Rakefile:11:in `read'
@@@

It looks like the gemspec file is missing from the gem distribution.

HEAD responds with a body

Seems like async_sinatra responds with a body when a HEAD request is made, where regular Sinatra works fine.

require 'sinatra/async'

class TestServer < Sinatra::Base
  register Sinatra::Async
  aget '/' do
    body('hello')
  end
end

TestServer.run!
>ruby -e "require 'socket'; s=TCPSocket.open('localhost',4567); s.write(\"HEAD / HTTP/1.0\r\n\r\n\"); while((d=s.recv(1)).length>0) do print(d); end"
HTTP/1.1 200 OK
Content-Length: 5
Connection: close
Server: thin 1.2.11 codename Bat-Shit Crazy

hello

Tests fail for async_sinatra 0.4.0

When I try to run the tests for async_sinatra 0.4.0 I get the following failures:

  1. Failure:
    test_aredirect(TestSinatraAsync)
    [./test/test_async.rb:100:in assert_redirect' ./test/test_async.rb:187:intest_aredirect']:
    <"http://example.org/"> expected but was
    <"/">

diff:
? http://example.org/

  1. Failure:
    test_emredirect(TestSinatraAsync)
    [./test/test_async.rb:100:in assert_redirect' ./test/test_async.rb:195:intest_emredirect']:
    <"http://example.org/"> expected but was
    <"/">

diff:
? http://example.org/

  1. Failure:
    test_redirect(TestSinatraAsync)
    [./test/test_async.rb:100:in assert_redirect' ./test/test_async.rb:180:intest_redirect']:
    <"http://example.org/"> expected but was
    <"/">

diff:
? http://example.org/

Please let me know if you need more information to further diagnose this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.