<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,8 @@
 Version 0.3.1, 15.10.08
 - fixed to autodiscovery code bugs. 
 - introduced Workling::VERSION
-- fixed AR reconnecting code for Multicore systems (Thanks Brent!)
+- fixed test suite for the case that no memcache client is installed at all
+- fixed AR reconnecting code for Multicore systems (Thanks Brent)
 
 Version 0.3, 25.09.08
 - added backgroundjob runner</diff>
      <filename>CHANGES.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,7 @@ module Workling
           
         @routing = routing
         @workers = ThreadGroup.new
+        @mutex = Mutex.new
       end      
       
       # returns the Workling::Base.logger
@@ -40,22 +41,28 @@ module Workling
         # Wait for all workers to complete
         @workers.list.each { |t| t.join }
 
+        logger.debug(&quot;Reaped listener threads. &quot;)
+        
         # Clean up all the connections.
         ActiveRecord::Base.verify_active_connections!
+        logger.debug(&quot;Cleaned up connection: out!&quot;)
+      end
+      
+      # Check if all Worker threads have been started. 
+      def started?
+        Workling::Discovery.discovered.size == @workers.list.size
       end
       
-      # gracefully stop processing
+      # Gracefully stop processing
       def stop
+        sleep 1 until started? # give it a chance to start up before shutting down. 
+        logger.info(&quot;Giving Listener Threads a chance to shut down. This may take a while... &quot;)
         @workers.list.each { |w| w[:shutdown] = true }
+        logger.info(&quot;Listener threads were shut down.  &quot;)
       end
-      
-      ##
-      ## Thread procs
-      ##
-      
+
       # Listen for one worker class
       def clazz_listen(clazz)
-        
         logger.debug(&quot;Listener thread #{clazz.name} started&quot;)
            
         # Read thread configuration if available
@@ -70,7 +77,7 @@ module Workling
                 
         # Setup connection to starling (one per thread)
         connection = Workling::Starling::Client.new
-        puts &quot;** Starting Workling::Starling::Client for #{clazz.name} queue&quot;
+        logger.info(&quot;** Starting Workling::Starling::Client for #{clazz.name} queue&quot;)
         
         # Start dispatching those messages
         while (!Thread.current[:shutdown]) do
@@ -87,7 +94,7 @@ module Workling
             #     threads would hit serious issues at this block of code without 
             #     the mutex.            
             #
-            Mutex.synchronize do 
+            @mutex.synchronize do 
               unless ActiveRecord::Base.connection.active?  # Keep MySQL connection alive
                 unless ActiveRecord::Base.connection.reconnect!
                   logger.fatal(&quot;Failed - Database not available!&quot;)</diff>
      <filename>lib/workling/starling/poller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ ActionController::Base.logger = Workling::Base.logger
 
 poller = Workling::Starling::Poller.new(Workling::Starling::Routing::ClassAndMethodRouting.new)
 
-trap(:INT) { exit }
+trap(:INT) { poller.stop; exit }
 
 begin
   poller.listen</diff>
      <filename>script/listen.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
 context &quot;the starling poller&quot; do
   setup do
     routing = Workling::Starling::Routing::ClassAndMethodRouting.new
+   
     # the memoryreturnstore behaves exactly like memcache. 
     @connection = Workling::Return::Store::MemoryReturnStore.new
     @client = Workling::Starling::Poller.new(routing)
@@ -13,4 +14,22 @@ context &quot;the starling poller&quot; do
     @connection.set(&quot;utils__echo&quot;, &quot;hello&quot;)
     @client.dispatch!(@connection, Util)
   end
+  
+  specify &quot;should not explode when listen is called, and stop nicely when stop is called. &quot; do
+    connection = mock()
+    connection.expects(:active?).at_least_once.returns(true)
+    ActiveRecord::Base.expects(:connection).at_least_once.returns(connection)
+    
+    client = mock()
+    client.expects(:get).at_least_once.returns(&quot;hi&quot;)
+    Workling::Starling::Client.expects(:new).at_least_once.returns(client)
+    
+    # Don't take longer than 10 seconds to shut this down. 
+    Timeout::timeout(10) do
+      listener = Thread.new { @client.listen }
+      @client.stop
+      listener.join
+    end
+    
+  end
 end
\ No newline at end of file</diff>
      <filename>test/starling_poller_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,16 +4,21 @@ plugin_lib = File.join plugin_root, 'lib'
 
 require 'rubygems'
 require 'active_support'
+require 'active_record'
 require 'test/spec'
 require 'mocha'
 
 $:.unshift plugin_lib, plugin_test
 
 RAILS_ENV = &quot;test&quot;
+RAILS_ROOT = File.dirname(__FILE__) + &quot;/..&quot; # fake the rails root directory.
+RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
+RAILS_DEFAULT_LOGGER.level = Logger::ERROR
 
 require &quot;mocks/spawn&quot;
 require &quot;mocks/logger&quot;
 require &quot;workling&quot;
+require &quot;workling/base&quot;
 
 Workling.try_load_a_memcache_client
 
@@ -29,9 +34,6 @@ require &quot;workling/return/store/memory_return_store&quot;
 require &quot;workling/return/store/starling_return_store&quot;
 require &quot;mocks/client&quot;
 
-RAILS_ROOT = File.dirname(__FILE__) + &quot;/..&quot; # fake the rails root directory.
-RAILS_DEFAULT_LOGGER = Logger.new
-
 # worklings are in here.
 Workling.load_path =&quot;#{ plugin_root }/test/workers&quot;
 Workling::Return::Store.instance = Workling::Return::Store::MemoryReturnStore.new</diff>
      <filename>test/test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ module Analytics
   class Invites &lt; ::Workling::Base
     
     def sent(*args)
-      p &quot;nice&quot;
+      logger.info(&quot;nice&quot;)
     end
   end
 end
\ No newline at end of file</diff>
      <filename>test/workers/analytics/invites.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,4 +12,4 @@ class Util &lt; Workling::Base
   def stuffing(contents)
     # expects contents. 
   end
-end
+end
\ No newline at end of file</diff>
      <filename>test/workers/util.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7328e545ccd0cd0a2f20993e08bde4c3ea7c8bc9</id>
    </parent>
  </parents>
  <author>
    <name>Rany Keddo</name>
    <email>rany@playtype.net</email>
  </author>
  <url>http://github.com/purzelrakete/workling/commit/339691c131d59298042f52ae7ed85fe9e312fcad</url>
  <id>339691c131d59298042f52ae7ed85fe9e312fcad</id>
  <committed-date>2008-10-17T03:13:42-07:00</committed-date>
  <authored-date>2008-10-17T03:13:42-07:00</authored-date>
  <message>fixed problem running tests when no memcache. added mutex to connection resetting, fixed graceful shutdown of worker threads, added graceful shutdown to runner script</message>
  <tree>f17dd1c7f1707a40a98742206de45fcdec257fe0</tree>
  <committer>
    <name>Rany Keddo</name>
    <email>rany@playtype.net</email>
  </committer>
</commit>
