jasmine / jasmine-gem

Jasmine ruby gem
682 stars 274 forks source link

'"Address already in use - bind(2)" error using jasmine:ci on v2.0.0 #187

Closed recurser closed 10 years ago

recurser commented 10 years ago

Running rake jasmine:ci on master seems to fail every time with an Address already in use error, no matter what port I specify. I've tried a variety of ports, and checked that nothing is running on the port using lsof -wni | grep <PORT NUMBER>.

There's a bare-bones rails install that exhibits the problem locally here: https://github.com/recurser/jasmine-2.0.0-address-already-in-use

rake jasmine works as expected.

[2014-01-07 10:25:06] INFO  WEBrick 1.3.1
[2014-01-07 10:25:06] INFO  ruby 2.0.0 (2013-11-22) [x86_64-darwin13.0.0]
[2014-01-07 10:25:06] INFO  WEBrick::HTTPServer#start: pid=37315 port=56789
Waiting for jasmine server on 56789...
jasmine server started.

5 specs, 0 failures
[2014-01-07 10:25:14] INFO  WEBrick 1.3.1
[2014-01-07 10:25:14] INFO  ruby 2.0.0 (2013-11-22) [x86_64-darwin13.0.0]
[2014-01-07 10:25:14] WARN  TCPServer Error: Address already in use - bind(2)
jasmine server started.
[2014-01-07 10:25:14] WARN  TCPServer Error: Address already in use - bind(2)
rake aborted!
Address already in use - bind(2)
/Users/dave/.rvm/gems/ruby-2.0.0-p353@shuttlerock/gems/rack-1.4.5/lib/rack/handler/webrick.rb:10:in `new'
/Users/dave/.rvm/gems/ruby-2.0.0-p353@shuttlerock/gems/rack-1.4.5/lib/rack/handler/webrick.rb:10:in `run'
/Users/dave/.rvm/gems/ruby-2.0.0-p353@shuttlerock/gems/rack-1.4.5/lib/rack/server.rb:268:in `start'
/Users/dave/.rvm/gems/ruby-2.0.0-p353@shuttlerock/bundler/gems/jasmine-gem-5f334f18d536/lib/jasmine/server.rb:16:in `start'
/Users/dave/.rvm/gems/ruby-2.0.0-p353@shuttlerock/bundler/gems/jasmine-gem-5f334f18d536/lib/jasmine/tasks/jasmine.rake:32:in `block (3 levels) in <top (required)>'
Tasks: TOP => jasmine:ci
(See full trace by running task with --trace)
[2014-01-07 10:25:17] INFO  going to shutdown ...
[2014-01-07 10:25:17] INFO  WEBrick::HTTPServer#start done.
tjarratt commented 10 years ago

Hey @recurser, this behavior is symptomatic of your jasmine tasks being defined multiple times. I was able to create a new rails 4 project, added the bleeding edge master jasmine-gem to my Gemfile and saw that rake jasmine:ci still worked.

Taking a look at your project, it seems like your Rakefile is the problem

Rakefile

#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

JasmineTest::Application.load_tasks
require 'jasmine'

# <<<<<this line causes the tasks to be defined again>>>>>
load 'jasmine/tasks/jasmine.rake'
recurser commented 10 years ago

Aha, I used 'jasmine init' rather than the generator, and it must have added that line. No 'address in use' problem when that line is removed.

Thanks!

tjarratt commented 10 years ago

Sounds like there is a real bug here then. Running jasmine init from inside a rails project is supposed to raise an exception.

https://github.com/pivotal/jasmine-gem/blob/master/lib/jasmine/command_line_tool.rb#L93

The bug is that this code assumes its current working directory is Rails.root, which is not guaranteed to be true. Unless you ran jasmine init --force, in which case it doesn't check at all.

recurser commented 10 years ago

@tjarratt sorry, it did raise an exception - I ran jasmine init --force. I tried running the rails generator but it complained that the generator didn't exist (which may be a bug?) so I used jasmine init instead.

ragaskar commented 10 years ago

The generator won't necessarily be found if you only install jasmine under the Gemfile test group (which many people do). You want it in test & development. If that was the case and you still didn't see the generator, sounds like we have a railtie bug.

recurser commented 10 years ago

@ragaskar yes jasmine was included under both test and development - see this example Gemfile.

The generator doesn't appear to be available for this test app:

> rails g jasmine:init
Could not find generator jasmine:init.
sheelc commented 10 years ago

@recurser It's currently set up to be rails g jasmine:install for rails projects and jasmine init otherwise. rails g jasmine:install seems to work correctly in your sample project.

Maybe the change that should be made is to make both of them consistent. Although I could see how the two different commands highlight that they do different things and are for different types of projects.

recurser commented 10 years ago

@sheelc thanks, jasmine:install works as expected. It was the output of jasmine init that was confusing me:

jasmine init

You're attempting to run jasmine init in a Rails project. You probably want to use the Rails generator like so:
    rails g jasmine:init

If you're not actually in a Rails application, just run this command again with --force
    jasmine init --force

I've added a pull request to update the help message.

sheelc commented 10 years ago

Ah yes, that is pretty confusing. Thanks for the pull; I'll merge it in after Travis is finished with the build.

recurser commented 10 years ago

Thanks @sheelc