I&#39;ve done some more work on this and have created a test case that reliably throws errors, although the errors themselves are not consistent.<br>About 1 out of every 4 times, I get the &quot;can&#39;t convert Symbol to Hash&quot; error in server/lib/backgroundrb/results.rb:40 in &#39;merge!&#39;. 
<br><br>I created the following worker class is {RAILS_ROOT}/lib/workers/results_test_worker.rb<br><br># This class repeatedly writes values to the results, to<br># test the results process<br>class ResultsTestWorker &lt; BackgrounDRb::Worker::RailsBase
<br>&nbsp; <br>&nbsp; def do_work(args)<br>&nbsp;&nbsp;&nbsp; <a href="http://logger.info">logger.info</a> &quot;Started ResultsTestWorker&quot;<br>&nbsp;&nbsp;&nbsp; results[:started_at] = Time.now<br>&nbsp;&nbsp;&nbsp; args ||= {}<br>&nbsp;&nbsp;&nbsp; limit = args[:limit] || 10_000<br>&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; <a href="http://logger.info">logger.info</a> &quot;Limit is #{limit}&quot;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; limit.times do |i|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results[:last_update] = Time.now<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results[:counter] = i<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; stop_time = Time.now
<br>&nbsp;&nbsp;&nbsp; <a href="http://logger.info">logger.info</a> &quot;Stopped ResultsTestWorker at #{stop_time}&quot;<br>&nbsp;&nbsp;&nbsp; results[:stopped_at] = stop_time<br>&nbsp;&nbsp;&nbsp; self.delete<br>&nbsp; end<br><br>end<br>ResultsTestWorker.register<br><br>
Then in {RAILS_ROOT}/test/unit/drb_results_test.rb&nbsp; I have:<br><br>require File.dirname(__FILE__) + &#39;/../test_helper&#39;<br><br>class DrbResultsTest &lt; Test::Unit::TestCase<br><br>&nbsp; def setup<br>&nbsp;&nbsp;&nbsp; # start backgroundrb server
<br>&nbsp;&nbsp;&nbsp; `../../script/backgroundrb start`<br>&nbsp;&nbsp;&nbsp; sleep 5 # give it time to startup<br>&nbsp; end<br>&nbsp; <br>&nbsp; def teardown<br>&nbsp;&nbsp;&nbsp; # stop backgroundrb server<br>&nbsp;&nbsp;&nbsp; `../../script/backgroundrb stop`<br>&nbsp; end<br>&nbsp; <br>&nbsp; def test_results
<br>&nbsp;&nbsp;&nbsp; limit = 10<br>&nbsp;&nbsp;&nbsp; keys = []<br>&nbsp;&nbsp;&nbsp; 4.times do |i|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; job_key = &quot;#{<a href="http://self.class.name">self.class.name</a>}_#{i}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keys &lt;&lt; job_key<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MiddleMan.new_worker(:class =&gt; :results_test_worker, :job_key =&gt; job_key, :args =&gt; {:limit =&gt; limit})
<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; sleep 2 # wait for workers to finish<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; keys.each_with_index do |k, i|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert_not_nil MiddleMan[k], &quot;checking job_key #{k} on iteration #{i}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert_not_nil MiddleMan[k].object, &quot;checking object on iteration #{i}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert_not_nil MiddleMan[k].object.results, &quot;checking results on iteration #{i}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert_equal(limit - 1, MiddleMan[k].object.results.to_hash[:counter], &quot;checking counter on iteration #{i}&quot;)
<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; end<br>end<br><br>This test does the following:<br>- Spawns 4 results_test_worker processes that each write several values to the ResultsWorker (in parallel)<br>Increasing the limit value increases the odds of these processes concurrently trying to write results at the
<br>same time, but I&#39;ve found that a limit of 10 works pretty well.<br>- It waits a couple seconds for the workers to finish (is there a better way to determine if the processes are all done)?<br>- Then it tries to access the results for each job_key, specifically to ensure that counter value is equal to limit - 1.
<br><br>NOTE: I&#39;ve never gotten this test to complete successfully. In addition to the &quot;can&#39;t convert Symbol to Hash&quot; error,<br>I&#39;ve seen the following:<br>- The [:counter] value is much lower than the expected value. If limit is 10,000 this value might be 246 when 9,999 was expected.
<br>- The job_key is not recognized, the call to MiddleMan[k] returns nil. When this occurs, I can usually see in the backgroundrb.log<br>&nbsp;&nbsp; that fewer than 4 workers were actually created. I can see this by counting the number of &quot;Started ResultsTestWorker&quot; 
<br>&nbsp;&nbsp; messages in the log.<br>- The job_key is resolved, but the call to MiddleMan[k].object.results returns nil<br>- The call to MiddleMan.new_worker hangs and never returns<br><br>I&#39;m sharing this code so that others can try it out. It&#39;s a bit of a hack to get some testing working (starting and stopping the BackgrounDRb server on each test, having a test worker class in lib/workers, etc.), but it is self-contained, and replicated the real-world environment of my code running in rails. It you have suggestions for improving the testing approach I&#39;m all ears.
<br><br>I&#39;m also interested in feedback in the code itself. Maybe I&#39;m not working with the MiddleMan object correctly. I have to admit I&#39;m still wrapping my head around Drb.<br><br>Resolving this issue is critical to my project so I will continue trying to track things down. I&#39;ll start by adding a mutex to the Results#[]= method.
<br><br>Mason<br><br><br><div><span class="gmail_quote">On 1/10/07, <b class="gmail_sendername">skaar</b> &lt;<a href="mailto:skaar@waste.org">skaar@waste.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It might be that we have to introduce a mutex in the results worker<br>where this happens. I&#39;ll try to get this reproduced sometime this<br>weekend.<br><br>/skaar<br><br><br></blockquote></div><br>