DEV: stabalize test suite

DEV: stabalize test suite

we needed to add a bit more sleep here unfortunately in wait_till_done to account for the time between we grab something from the queue and the time we figure out it is running

diff --git a/lib/mini_scheduler/manager.rb b/lib/mini_scheduler/manager.rb
index d84f654..b016ecd 100644
--- a/lib/mini_scheduler/manager.rb
+++ b/lib/mini_scheduler/manager.rb
@@ -10,6 +10,8 @@ module MiniScheduler
         @mutex = Mutex.new
         @queue = Queue.new
         @manager = manager
+        @hostname = manager.hostname
+
         @reschedule_orphans_thread = Thread.new do
           while !@stopped
             sleep 60
@@ -47,20 +49,17 @@ module MiniScheduler
       end
 
       def hostname
-        @hostname ||= begin
-                        `hostname`
-                      rescue
-                        "unknown"
-                      end
+        @hostname
       end
 
       def process_queue
 
         klass = @queue.deq
-        return unless klass
-
         # hack alert, I need to both deq and set @running atomically.
         @running = true
+
+        return if !klass
+
         failed = false
         start = Time.now.to_f
         info = @mutex.synchronize { @manager.schedule_info(klass) }
@@ -147,7 +146,8 @@ module MiniScheduler
           sleep 0.001
         end
         # this is a hack, but is only used for test anyway
-        sleep 0.001
+        # if tests fail that depend on this we are forced to increase it.
+        sleep 0.010
         while @running
           sleep 0.001
         end
@@ -171,7 +171,6 @@ module MiniScheduler
 
     def initialize(options = nil)
       @queue = options && options[:queue] || "default"
-
       @redis = MiniScheduler.redis
       @random_ratio = 0.1
       unless options && options[:skip_runner]
@@ -194,7 +193,11 @@ module MiniScheduler
     end
 
     def hostname
-      @hostname ||= `hostname`.strip
+      @hostname ||= begin
+                      `hostname`.strip
+                    rescue
+                      "unknown"
+                    end
     end
 
     def schedule_info(klass)
diff --git a/spec/mini_scheduler/manager_spec.rb b/spec/mini_scheduler/manager_spec.rb
index 116eaa5..60b932e 100644
--- a/spec/mini_scheduler/manager_spec.rb
+++ b/spec/mini_scheduler/manager_spec.rb
@@ -60,6 +60,7 @@ describe MiniScheduler::Manager do
   let(:redis) { MockRedis.new }
 
   before do
+
     MiniScheduler.configure do |config|
       config.redis = redis
     end
@@ -121,16 +122,17 @@ describe MiniScheduler::Manager do
   it 'can disable stats' do
     manager = MiniScheduler::Manager.new(enable_stats: false)
     expect(manager.enable_stats).to eq(false)
+
     manager.stop!
 
     manager = MiniScheduler::Manager.new
     expect(manager.enable_stats).to eq(false)
     manager.stop!
+
   end
 
   describe 'per host jobs' do
     it "correctly schedules on multiple hosts" do
-
       freeze_time
 
       Testing::PerHostJob.runs = 0
@@ -175,7 +177,6 @@ describe MiniScheduler::Manager do
     end
 
     it 'should recover from crashed manager' do
-
       info = manager.schedule_info(Testing::SuperLongJob)
       info.next_run = Time.now.to_i - 1
       info.write!
@@ -194,28 +195,6 @@ describe MiniScheduler::Manager do
       manager.stop!
     end
 
-    # we have no database here
-    pending 'should log when job finishes running' do
-
-      Testing::RandomJob.runs = 0
-
-      info = manager.schedule_info(Testing::RandomJob)
-      info.next_run = Time.now.to_i - 1
-      info.write!
-
-      # with stats so we must be careful to cleanup
-      manager = MiniScheduler::Manager.new
-      manager.blocking_tick
-      manager.stop!
-
-      # TODO: we have no database
-      stat = MiniScheduler::Stat.first
-      expect(stat).to be_present
-      expect(stat.duration_ms).to be > 0
-      expect(stat.success).to be true
-      MiniScheduler::Stat.destroy_all
-    end
-
     it 'should only run pending job once' do
 
       Testing::RandomJob.runs = 0
@@ -250,7 +229,6 @@ describe MiniScheduler::Manager do
 
   describe '#next_run' do
     it 'should be within the next 5 mins if it never ran' do
-
       manager.remove(Testing::RandomJob)
       manager.ensure_schedule!(Testing::RandomJob)
 
diff --git a/spec/mini_scheduler/schedule_info_spec.rb b/spec/mini_scheduler/schedule_info_spec.rb
index bc27bb1..28f0fe4 100644
--- a/spec/mini_scheduler/schedule_info_spec.rb
+++ b/spec/mini_scheduler/schedule_info_spec.rb
@@ -12,6 +12,10 @@ describe MiniScheduler::ScheduleInfo do
     end
   end
 
+  after do
+    manager.stop!
+  end
+
   context "every" do
     class RandomJob
       extend ::MiniScheduler::Schedule

GitHub sha: 9d3f7717