Skip to content
This repository
Browse code

Merge branch 'master' into trinidad

  • Loading branch information...
commit 06f31f0b610d96e5aa23e1fc7084f6ead39fe224 2 parents c072e24 + 2cbe42e
Konstantin Haase rkh authored

Showing 2 changed files with 56 additions and 4 deletions. Show diff stats Hide diff stats

  1. +1 3 test/integration/app.rb
  2. +55 1 test/integration_helper.rb
4 test/integration/app.rb
@@ -47,9 +47,7 @@
47 47 class Subclass < Sinatra::Base
48 48 set :out, nil
49 49 get '/subclass/async' do
50   - settings.out << msg and halt(204) if params[:msg]
51   - settings.out.close and halt(204) if params[:close]
52   - stream(:keep_open) { |o| settings.out = o }
  50 + stream(:keep_open) { |o| (settings.out = o) << "hi!" }
53 51 end
54 52
55 53 get '/subclass/send' do
56 test/integration_helper.rb
@@ -4,7 +4,7 @@
4 4 require 'net/http'
5 5
6 6 module IntegrationHelper
7   - class Server
  7 + class BaseServer
8 8 extend Enumerable
9 9 attr_accessor :server, :port, :pipe
10 10 alias name server
@@ -127,6 +127,60 @@ def webrick?
127 127 end
128 128 end
129 129
  130 + if RUBY_ENGINE == "jruby"
  131 + class JRubyServer < BaseServer
  132 + def start_vm
  133 + require 'java'
  134 + # Create a new container, set load paths and env
  135 + # SINGLETHREAD means create a new runtime
  136 + vm = org.jruby.embed.ScriptingContainer.new(org.jruby.embed.LocalContextScope::SINGLETHREAD)
  137 + vm.load_paths = [File.expand_path('../../lib', __FILE__)]
  138 + vm.environment = ENV.merge('RACK_ENV' => environment.to_s)
  139 +
  140 + # This ensures processing of RUBYOPT which activates Bundler
  141 + vm.provider.ruby_instance_config.process_arguments []
  142 + vm.argv = ['-s', server.to_s, '-o', '127.0.0.1', '-p', port.to_s, '-e', environment.to_s]
  143 +
  144 + # Set stdout/stderr so we can retrieve log
  145 + @pipe = java.io.ByteArrayOutputStream.new
  146 + vm.output = java.io.PrintStream.new(@pipe)
  147 + vm.error = java.io.PrintStream.new(@pipe)
  148 +
  149 + Thread.new do
  150 + # Hack to ensure that Kernel#caller has the same info as
  151 + # when run from command-line, for Sintra::Application.app_file.
  152 + # Also, line numbers are zero-based in JRuby's parser
  153 + vm.provider.runtime.current_context.set_file_and_line(app_file, 0)
  154 + # Run the app
  155 + vm.run_scriptlet org.jruby.embed.PathType::ABSOLUTE, app_file
  156 + # terminate launches at_exit hooks which start server
  157 + vm.terminate
  158 + end
  159 + end
  160 +
  161 + def run
  162 + return unless installed?
  163 + kill
  164 + @thread = start_vm
  165 + @started = Time.now
  166 + warn "#{server} up and running on port #{port}" if ping
  167 + at_exit { kill }
  168 + end
  169 +
  170 + def log
  171 + String.from_java_bytes @pipe.to_byte_array
  172 + end
  173 +
  174 + def kill
  175 + @thread.kill if @thread
  176 + @thread = nil
  177 + end
  178 + end
  179 + Server = JRubyServer
  180 + else
  181 + Server = BaseServer
  182 + end
  183 +
130 184 def it(message, &block)
131 185 Server.each do |server|
132 186 next unless server.installed?

0 comments on commit 06f31f0

Please sign in to comment.
Something went wrong with that request. Please try again.