Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show inotify limit error *before* calling abort #218

Merged
merged 1 commit into from Apr 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/listen/adapter/linux.rb
Expand Up @@ -14,7 +14,7 @@ class Linux < Base
# The message to show when the limit of inotify watchers is not enough
#
INOTIFY_LIMIT_MESSAGE = <<-EOS.gsub(/^\s*/, '')
Listen error: unable to monitor directories for changes.
FATAL: Listen error: unable to monitor directories for changes.

Please head to https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
for information on how to solve this issue.
Expand All @@ -33,6 +33,8 @@ def start
worker = _init_worker
Thread.new { worker.run }
rescue Errno::ENOSPC
STDERR.puts INOTIFY_LIMIT_MESSAGE
STDERR.flush
abort(INOTIFY_LIMIT_MESSAGE)
end

Expand Down
20 changes: 20 additions & 0 deletions spec/lib/listen/adapter/linux_spec.rb
Expand Up @@ -17,6 +17,26 @@
expect(defined?(INotify)).to be_true
end
end

# workaround: Celluloid ignores SystemExit exception messages
describe "inotify limit message" do
let(:adapter) { described_class.new(listener) }
let(:expected_message) { described_class.const_get('INOTIFY_LIMIT_MESSAGE') }

before do
allow_any_instance_of(INotify::Notifier).to receive(:watch).and_raise(Errno::ENOSPC)
allow(listener).to receive(:directories) { [ 'foo/dir' ] }
end

it "should be show before calling abort" do
expect(STDERR).to receive(:puts).with(expected_message)

# Expect RuntimeError here, for the sake of unit testing (actual
# handling depends on Celluloid supervisor setup, which is beyond the
# scope of adapter tests)
expect{adapter.start}.to raise_error RuntimeError, expected_message
end
end
end

if darwin?
Expand Down