Skip to content

Commit

Permalink
Merge de8125b into 4d9d065
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Aug 22, 2015
2 parents 4d9d065 + de8125b commit 028ec88
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--color
--format documentation
--require spec_helper
#TODO: remove
--fail-fast
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: ruby
bundler_args: --without development
rvm:
- 2.2.2
- jruby-head
- rbx-2
# - jruby-head
# - rbx-2
matrix:
allow_failures:
- rvm: jruby-head
Expand All @@ -14,8 +14,10 @@ matrix:
- rvm: rbx-2
os: osx
os:
- linux
# - linux
- osx
env:
- LISTEN_TESTS_DEFAULT_LAG=0.8
# TODO: 0.8 is enough on Linux, but 1.1 is needed for OSX
- LISTEN_TESTS_DEFAULT_LAG=1.1 LISTEN_GEM_DEBUGGING=2 TEST_LISTEN_ADAPTER_MODES='native' FWDEBUG=1
# TODO: undo
sudo: false
1 change: 1 addition & 0 deletions lib/listen/adapter/darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _configure(dir, &callback)

@workers ||= ::Queue.new
@workers << FSEvent.new.tap do |worker|
STDERR.puts "WATCHING: #{dir.to_s} with latency: #{options.latency}"
worker.watch(dir.to_s, opts, &callback)
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/acceptance/listen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@
end

it 'listens to dir move' do
logger = ::Logger.new(STDERR)
logger.level = Logger::DEBUG
expected = { modified: [],
added: ['dir2/dir1/file1.rb'],
removed: ['dir1/file1.rb'] }

expect(wrapper.listen do
logger.debug "doing the move"
mv 'dir1', 'dir2/'
logger.debug "done with the move"
end).to eq expected
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/listen/adapter/linux_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
let(:adapter_options) { { events: [:recursive, :close_write] } }

before do
allow(Kernel).to receive(:require).with('rb-inotify')
fake_worker = double(:fake_worker)
events = [:recursive, :close_write]
allow(fake_worker).to receive(:watch).with('/foo/dir1', *events)
Expand All @@ -78,6 +77,7 @@
allow(Listen::Change).to receive(:new).with(config, record).
and_return(snapshot)

allow(subject).to receive(:require).with('rb-inotify')
subject.configure
end

Expand Down
16 changes: 15 additions & 1 deletion spec/support/acceptance_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'logger'

{
modification: :modified,
addition: :added,
Expand Down Expand Up @@ -109,6 +111,9 @@ def initialize
# Set to non-nil, because changes can immediately come after unpausing
# listener in an Rspec 'before()' block
@changes = { modified: [], added: [], removed: [] }

@logger = ::Logger.new(STDERR)
@logger.level = Logger::DEBUG
end

def change_offset
Expand Down Expand Up @@ -136,7 +141,9 @@ def allow_changes(reset_queue = true)
end

@yield_time = Time.now.to_f
@logger.debug "allow_changes - yield"
yield
@logger.debug "allow_changes - done yield, freezing"
# Prevent recording changes after timeout
@changes.freeze
@freeze_time = Time.now.to_f
Expand All @@ -159,6 +166,9 @@ def initialize(callback, paths, *args)
# notification, which for polling and FSEvent means the configured latency
@lag = Float(ENV['LISTEN_TESTS_DEFAULT_LAG'] || 0.2)

@logger = ::Logger.new(STDERR)
@logger.level = Logger::DEBUG

@paths = paths

# Isolate collected changes between tests/listener instances
Expand Down Expand Up @@ -191,7 +201,9 @@ def listen(reset_queue = true)

@timed_changes.allow_changes(reset_queue) do

@logger.debug "timed changes - running block doing the changes"
yield
@logger.debug "timed changes - done block doing the changes"

# Polling sleep (default: 1s)
backend = @listener.instance_variable_get(:@backend)
Expand All @@ -201,15 +213,17 @@ def listen(reset_queue = true)
# Lag should include:
# 0.1s - 0.2s if the test needs Listener queue to be processed
# 0.1s in case the system is busy
# 0.1s - for celluloid overhead and scheduling
sleep lag
@logger.debug "timed changes - done waiting for events (#{lag})"
end

# Keep this to detect a lag too small (changes during this sleep
# will trigger "frozen hash" error caught below (and displaying timeout
# details)
sleep 1

@logger.debug "timed changes - done waiting for late events (#{lag})"

changes
end

Expand Down

0 comments on commit 028ec88

Please sign in to comment.