1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Stop EventedFileUpdateChecker's listener only

When an `EventedFileUpdateChecker` instance detects a watched directory
that previously did not exist, it calls `shutdown!` and then `boot!` to
reinitialize its underlying listener.  Prior to this commit, `shutdown!`
invoked `Listen.stop` which stops **all** listeners, globally.  This
commit changes `shutdown!` to stop the checker's listener only.

Fixes #38174.
This commit is contained in:
Jonathan Hefner 2020-08-24 19:56:40 -05:00
parent 7387b85ebb
commit 6601acf268
2 changed files with 23 additions and 2 deletions

View file

@ -100,11 +100,12 @@ module ActiveSupport
def boot!
normalize_dirs!
Listen.to(*@dtw, &method(:changed)).start if @dtw.any?
@listener = @dtw.any? ? Listen.to(*@dtw, &method(:changed)) : nil
@listener&.start
end
def shutdown!
Listen.stop
@listener&.stop
end
def normalize_dirs!

View file

@ -120,6 +120,26 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase
assert_not_predicate checker, :updated?
assert_not checker.execute_if_updated
end
test "does not stop other checkers when nonexistent directory is added later" do
dir1 = File.join(tmpdir, "app")
dir2 = File.join(tmpdir, "test")
Dir.mkdir(dir2)
checker1 = new_checker([], dir1 => ".rb") { }
checker2 = new_checker([], dir2 => ".rb") { }
Dir.mkdir(dir1)
touch(File.join(dir1, "a.rb"))
assert_predicate checker1, :updated?
assert_not_predicate checker2, :updated?
touch(File.join(dir2, "a.rb"))
assert_predicate checker2, :updated?
end
end
class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase