Skip to content

Commit

Permalink
JRuby compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptepper committed Mar 4, 2013
1 parent 3198c58 commit 5a050b8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 140 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -10,8 +10,8 @@ group :development, :test do
gem "bundler", "~> 1.0"
gem "rspec", "~> 2.6"
gem "jeweler", "~> 1.6"
gem "thin", "~> 1.5"
gem "unicorn", "~> 4.5"
gem "thin", "~> 1.5", :platform => :ruby
gem "unicorn", "~> 4.5", :platform => :ruby
gem "puma", "~> 1.6"
gem "em-http-request", "~> 1.0"
end
157 changes: 78 additions & 79 deletions spec/lib/heroku/forward/backends/thin_spec.rb
@@ -1,94 +1,93 @@
require 'spec_helper'
require 'heroku/forward/backends/thin'
unless RUBY_PLATFORM == "java"
require 'spec_helper'
require 'heroku/forward/backends/thin'

describe Heroku::Forward::Backends::Thin do

describe "without ssl" do
let(:backend) do
Heroku::Forward::Backends::Thin.new
end

after do
backend.terminate!
end

it "#spawned?" do
backend.spawned?.should be_false
end

it "doesn't generate socket file" do
File.exists?(backend.socket).should_not be_true
end
describe Heroku::Forward::Backends::Thin do
describe "without ssl" do
let(:backend) do
Heroku::Forward::Backends::Thin.new
end

context "checks" do
it "checks for application" do
expect {
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendOptionError
after do
backend.terminate!
end

it "checks that the application file exists" do
expect {
backend.application = 'spec/foobar'
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendApplicationError
it "#spawned?" do
backend.spawned?.should be_false
end

end

describe "#spawn!" do
before do
backend.application = "spec/support/app.ru"
it "doesn't generate socket file" do
File.exists?(backend.socket).should_not be_true
end

it "starts successfully" do
backend.spawn!.should_not == 0
sleep 2
backend.terminate!.should be_true

context "checks" do
it "checks for application" do
expect {
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendOptionError
end

it "checks that the application file exists" do
expect {
backend.application = 'spec/foobar'
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendApplicationError
end

end

it "generates socket file that outlives garbage-collection" do
backend.spawn!
sleep 2
lambda { GC.start }.should_not raise_error
File.exists?(backend.socket).should be_true

describe "#spawn!" do
before do
backend.application = "spec/support/app.ru"
end

it "starts successfully" do
backend.spawn!.should_not == 0
sleep 2
backend.terminate!.should be_true
end

it "generates socket file that outlives garbage-collection" do
backend.spawn!
sleep 2
lambda { GC.start }.should_not raise_error
File.exists?(backend.socket).should be_true
end
end

end

end

describe "with SSL" do
let(:application) { "spec/support/app.ru" }
let(:mock_ssl_cert_file) { "foo" }
let(:mock_ssl_key_file) { "bar" }
let(:socket) { "foobar" }
describe "with SSL" do
let(:application) { "spec/support/app.ru" }
let(:mock_ssl_cert_file) { "foo" }
let(:mock_ssl_key_file) { "bar" }
let(:socket) { "foobar" }

let(:backend) do
Heroku::Forward::Backends::Thin.new({
:application => application,
:socket => socket,
:ssl => true,
:ssl_verify => true,
:ssl_key_file => mock_ssl_key_file,
:ssl_cert_file => mock_ssl_cert_file
})
end
let(:backend) do
Heroku::Forward::Backends::Thin.new({
:application => application,
:socket => socket,
:ssl => true,
:ssl_verify => true,
:ssl_key_file => mock_ssl_key_file,
:ssl_cert_file => mock_ssl_cert_file
})
end

it "forward SSL arguments on spawning" do
cmd = []
cmd.push "thin"
cmd.push "start"
cmd.push "-R", application
cmd.push "--socket", socket
cmd.push "-e", "development"
cmd.push "--ssl"
cmd.push "--ssl-key-file", mock_ssl_key_file
cmd.push "--ssl-cert-file", mock_ssl_cert_file
cmd.push "--ssl-verify"
Spoon.should_receive(:spawnp).with(* cmd).and_return(0)
backend.spawn!
it "forward SSL arguments on spawning" do
cmd = []
cmd.push "thin"
cmd.push "start"
cmd.push "-R", application
cmd.push "--socket", socket
cmd.push "-e", "development"
cmd.push "--ssl"
cmd.push "--ssl-key-file", mock_ssl_key_file
cmd.push "--ssl-cert-file", mock_ssl_cert_file
cmd.push "--ssl-verify"
Spoon.should_receive(:spawnp).with(* cmd).and_return(0)
backend.spawn!
end
end

end
end

end
96 changes: 48 additions & 48 deletions spec/lib/heroku/forward/backends/unicorn_spec.rb
@@ -1,61 +1,61 @@
require 'spec_helper'
require 'heroku/forward/backends/unicorn'
unless RUBY_PLATFORM == "java"
require 'spec_helper'
require 'heroku/forward/backends/unicorn'

describe Heroku::Forward::Backends::Unicorn do
describe Heroku::Forward::Backends::Unicorn do

describe "with defaults" do
let(:backend) do
Heroku::Forward::Backends::Unicorn.new
end

after do
backend.terminate!
end
describe "with defaults" do
let(:backend) do
Heroku::Forward::Backends::Unicorn.new
end

it "#spawned?" do
backend.spawned?.should be_false
end
after do
backend.terminate!
end

context "checks" do
it "checks for application" do
expect {
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendOptionError
it "#spawned?" do
backend.spawned?.should be_false
end

it "checks that the application file exists" do
expect {
backend.application = 'spec/foobar'
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendApplicationError
context "checks" do
it "checks for application" do
expect {
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendOptionError
end

it "checks that the application file exists" do
expect {
backend.application = 'spec/foobar'
backend.spawn!
}.to raise_error Heroku::Forward::Errors::MissingBackendApplicationError
end

end

it "#spawn!" do
backend.application = "spec/support/app.ru"
backend.spawn!.should_not == 0
sleep 2
backend.terminate!.should be_true
end
end

it "#spawn!" do
backend.application = "spec/support/app.ru"
backend.spawn!.should_not == 0
sleep 2
backend.terminate!.should be_true
end
end

context "constructs command" do

let(:backend) do
Heroku::Forward::Backends::Unicorn.new(
:application => 'spec/support/app.ru',
:env => 'test',
:socket => '/tmp/unicorn.sock',
:config_file => 'spec/support/unicorn.rb'
)
end
context "constructs command" do

it "forwards arguments to spawner" do
Spoon.should_receive(:spawnp).with(*%w{unicorn --env test --config-file spec/support/unicorn.rb --listen /tmp/unicorn.sock spec/support/app.ru}).and_return(0)
backend.spawn!
end
let(:backend) do
Heroku::Forward::Backends::Unicorn.new(
:application => 'spec/support/app.ru',
:env => 'test',
:socket => '/tmp/unicorn.sock',
:config_file => 'spec/support/unicorn.rb'
)
end

it "forwards arguments to spawner" do
Spoon.should_receive(:spawnp).with(*%w{unicorn --env test --config-file spec/support/unicorn.rb --listen /tmp/unicorn.sock spec/support/app.ru}).and_return(0)
backend.spawn!
end
end
end
end

end
19 changes: 8 additions & 11 deletions spec/lib/heroku/forward/proxy/server_spec.rb
Expand Up @@ -5,14 +5,15 @@

describe Heroku::Forward::Proxy::Server do

[
Heroku::Forward::Backends::Thin,
Heroku::Forward::Backends::Unicorn,
Heroku::Forward::Backends::Puma
].each do |backend_type|
backends = [Heroku::Forward::Backends::Puma]

context "with #{backend_type.name} backend" do
unless RUBY_PLATFORM == "java"
backends << Heroku::Forward::Backends::Thin
backends << Heroku::Forward::Backends::Unicorn
end

backends.each do |backend_type|
context "with #{backend_type.name} backend" do
let(:backend) do
backend_type.new(:application => 'spec/support/app.ru')
end
Expand All @@ -22,7 +23,6 @@
end

context "spawned backend" do

before :each do
server.logger = Logger.new(STDOUT)
end
Expand All @@ -44,9 +44,6 @@
end
end
end

end
end

end

end

4 comments on commit 5a050b8

@dblock
Copy link

@dblock dblock commented on 5a050b8 Mar 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking forward to a pull request :)

@filiptepper
Copy link
Owner Author

@filiptepper filiptepper commented on 5a050b8 Mar 6, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock
Copy link

@dblock dblock commented on 5a050b8 Mar 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had looked at the EM code a while ago, there's quite a bit to write to get unix socket support into that. You should open an issue in em-proxy with whatever detail you have so far, someone will surely want the challenge if you're not already on it.

@dblock
Copy link

@dblock dblock commented on 5a050b8 Mar 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened igrigorik/em-proxy#39 actually, wanted to reference it in README.

Please sign in to comment.