ewollesen / autotest-inotify

Teaches autotest to use inotify (on Linux) instead of filesystem polling.
http://kill-0.com/projects/autotest-inotify
MIT License
18 stars 7 forks source link

autotest immediately exits when using latest code #11

Open jryan727 opened 13 years ago

jryan727 commented 13 years ago

On Ubuntu 10.10, Rails 3.0.3, Ruby 1.9.2, and Autotest 4.4.6, autotest-inotify 0.0.5 works, but often fails to catch file changes for some reason. I noticed there have been a few changes to the code, so I pulled the latest from here, and it causes autotest to immediately exit. I narrowed this down to a change made in acb3acec1b5d9002dc67, where the first_time_run? method was changed to return @notifier.nil?, the problem is that setup_inotify is called before first_time_run? is required, thus @notifier is already set, and first_time_run? always returns false. Reverting back to using self.last_mtime works for me, I'm not sure if that was causing other issues that prompted it to be changed in the first place or not. Anyway, here's my diff:

diff --git a/lib/autotest/inotify.rb b/lib/autotest/inotify.rb
index f36ee8d..2d3b582 100644
--- a/lib/autotest/inotify.rb
+++ b/lib/autotest/inotify.rb
@@ -65,7 +65,7 @@ module Autotest::Inotify
   end

   def first_time_run?
-    @notifier.nil?
+    self.last_mtime.to_i.zero?
   end

   def setup_inotify

Thanks for this awesome gem, I use it every day and it has been serving me well!

Thanks, Jim

jryan727 commented 13 years ago

Actually, after reviewing the code again, I see that this breaks autotest -f. I think this is the real solution:

diff --git a/lib/autotest/inotify.rb b/lib/autotest/inotify.rb
index f36ee8d..53eb295 100644
--- a/lib/autotest/inotify.rb
+++ b/lib/autotest/inotify.rb
@@ -26,7 +26,6 @@ module Autotest::Inotify
   def setup_inotify_if_running_linux
     if running_linux?
       override_autotest_methods
-      setup_inotify
     end
   end

We don't need to call setup_inotify while initializing, it'll be called when find_files_to_test is called if this is the first run. This solves the issue I eluded to before, because now first_time_run? is called before setup_inotify, so @notifier is nil when it should be. I tested this and it works with and without the -f flag.

Jim

medihack commented 13 years ago

Jim, I tried your solution, but unfortunately when starting autotest with autotest -c -f and pressing CTRL-C doesn't run all tests anymore (like it normally does).

jimryan commented 13 years ago

Ah sorry about that! I'm not on Linux and don't really use Autotest anymore, so I can't test this. If I have some time one of these days, I'll set up a Linux VM and try to troubleshoot. I wasn't very familiar with the code and wasn't very sure of my solution in the first place.

I see some recent activity working on the exact methods that I narrowed my issues down to, so it's very possible that this was fixed since you posted this comment.

filipegiusti commented 12 years ago

autotest -f isn't working on 0.0.6. Verbose shows the files changes are happening but no tests are run, CTRL + C didn't run the full suite either.