Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 1052c195bbf5702688368054f87a2f5cb5db7d5a 0 parents
@phiggins authored
6 History.txt
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2011-06-12
+
+* 1 major enhancement
+
+ * Birthday!
+
6 Manifest.txt
@@ -0,0 +1,6 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/thin/async/test.rb
+test/test_thin_async_test.rb
57 README.txt
@@ -0,0 +1,57 @@
+= thin_async_test
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== DEVELOPERS:
+
+After checking out the source, run:
+
+ $ rake newb
+
+This task will install any missing dependencies, run the tests/specs,
+and generate the RDoc.
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2011 FIX
+
+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.
18 Rakefile
@@ -0,0 +1,18 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.plugin :minitest
+Hoe.plugin :git
+
+Hoe.spec 'thin-async-test' do
+ developer('pete higgins', 'pete@peterhiggins.org')
+
+ extra_dev_deps << ["thin_async", "~> 0.1.0"]
+ extra_dev_deps << ["rack-test", "~> 0.6.0"]
+
+ self.testlib = :minitest
+end
+
+# vim: syntax=ruby
37 lib/thin/async/test.rb
@@ -0,0 +1,37 @@
+require 'eventmachine'
+require 'thin/async'
+
+module Thin
+ module Async
+ class Test
+ VERSION = '1.0.0'
+ class Callback
+ attr_reader :status, :headers, :body
+
+ def call args
+ @status, @headers, deferred_body = args
+ @body = ""
+ deferred_body.each {|s| @body << s }
+
+ deferred_body.callback { EM.stop }
+ end
+ end
+
+ def initialize(app, options={})
+ @app = app
+ end
+
+ def call(env)
+ callback = Callback.new
+ env.merge! 'async.callback' => callback
+ EM.run do
+ result = @app.call(env)
+
+ return result unless result == Thin::AsyncResponse::Marker
+ end
+
+ [callback.status, callback.headers, callback.body]
+ end
+ end
+ end
+end
49 test/test_thin_async_test.rb
@@ -0,0 +1,49 @@
+require "rack/test"
+require "thin/async/test"
+
+STATUS = 200
+HEADERS = {"X-Foo" => "bar"}
+BODY = "o hai!"
+
+TestApp = lambda do |env|
+ case env['PATH_INFO']
+ when '/sync'
+ [STATUS, HEADERS, BODY]
+ when '/async'
+ response = Thin::AsyncResponse.new(env, STATUS, HEADERS)
+
+ response << BODY
+
+ EM.add_timer(0.1) do
+ response << BODY
+
+ response.done
+ end
+
+ response.finish
+ end
+end
+
+describe Thin::Async::Test do
+ include Rack::Test::Methods
+
+ def app
+ Thin::Async::Test.new(TestApp)
+ end
+
+ it "returns normal response for syncronous action" do
+ get "/sync"
+
+ assert_equal STATUS, last_response.status
+ assert_equal "bar", last_response.headers["X-Foo"]
+ assert_equal BODY, last_response.body
+ end
+
+ it "returns async response for asyncronous action" do
+ get "/async"
+
+ assert_equal STATUS, last_response.status
+ assert_equal "bar", last_response.headers["X-Foo"]
+ assert_equal BODY*2, last_response.body
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.