Browse files

fix all the failing test cases and update for rails 2.3

  • Loading branch information...
1 parent 0922ade commit 226683600770ab163cf2dd248e254eb880b4c099 @gnufied committed Mar 29, 2009
View
12 Rakefile
@@ -4,7 +4,6 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'spec/rake/spectask'
require 'rake/contrib/sshpublisher'
-require "darkfish-rdoc"
desc 'Default: run unit tests.'
task :default => :test
@@ -32,21 +31,14 @@ desc 'Generate documentation for the backgroundrb plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc/output/manual'
rdoc.title = 'Backgroundrb'
- #rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('LICENSE')
rdoc.rdoc_files.include('lib/*.rb')
rdoc.rdoc_files.include('lib/backgroundrb/*.rb')
rdoc.rdoc_files.include('server/*.rb')
rdoc.rdoc_files.include('server/lib/*.rb')
- #rdoc.template = 'jamis'
- rdoc.options += [
- '-w', '4',
- '-SHN',
- '-f', 'darkfish', # This bit
- '-m', 'README',
- ]
-
+ rdoc.template = 'jamis'
end
module Rake
View
7 server/lib/master_proxy.rb
@@ -126,7 +126,12 @@ def load_rails_env
db_config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/database.yml")).result)
run_env = ENV["RAILS_ENV"]
ActiveRecord::Base.establish_connection(db_config_file[run_env])
- ActiveRecord::Base.allow_concurrency = true
+
+ if(Object.const_defined?(:Rails) && Rails.version < "2.2.2")
+ ActiveRecord::Base.allow_concurrency = true
+ elsif(Object.const_defined?(:RAILS_GEM_VERSION) && RAILS_GEM_VERSION < "2.2.2")
+ ActiveRecord::Base.allow_concurrency = true
+ end
end
def check_for_ruby_version; RUBY_VERSION >= "1.8.5"; end
View
6 server/lib/meta_worker.rb
@@ -411,7 +411,11 @@ def load_rails_env
db_config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/database.yml")).result)
run_env = ENV["RAILS_ENV"]
ActiveRecord::Base.establish_connection(db_config_file[run_env])
- ActiveRecord::Base.allow_concurrency = true
+ if(Object.const_defined?(:Rails) && Rails.version < "2.2.2")
+ ActiveRecord::Base.allow_concurrency = true
+ elsif(Object.const_defined?(:RAILS_GEM_VERSION) && RAILS_GEM_VERSION < "2.2.2")
+ ActiveRecord::Base.allow_concurrency = true
+ end
end
end # end of class MetaWorker
View
2 test/client/test_worker_proxy.rb
@@ -21,7 +21,7 @@
specify "should let you invoke sync task methods" do
actual_conn = mock()
actual_conn.expects(:server_info).returns("localhost:11008")
- actual_conn.expects(:send_request).returns(20)
+ actual_conn.expects(:send_request).returns({ :data => 20, :result_flag => "ok",:result => true, :type => :response})
@cluster_conn.expects(:choose_server).returns(actual_conn)
a = @worker_proxy.hello_world(:args => "sucks")
a.should == 20
View
1 test/server/test_master_proxy.rb
@@ -24,6 +24,7 @@
@master_proxy.worker_triggers.should.not.be {}
assert @master_proxy.worker_triggers.keys.include?(:bar_worker)
assert @master_proxy.worker_triggers[:bar_worker].keys.include?(:do_job)
+
@master_proxy.worker_triggers[:bar_worker][:do_job].should.not.be { }
end
View
36 test/server/test_master_worker.rb
@@ -2,7 +2,7 @@
context "Master Worker in general should" do
- def dump_object data
+ def packet_dump data
t = Marshal.dump(data)
t.length.to_s.rjust(9,'0') + t
end
@@ -13,6 +13,7 @@ def dump_object data
class << @master_worker
attr_accessor :outgoing_data
attr_accessor :key,:live_workers,:excpetion_type
+ attr_accessor :going_to_user
def packet_classify(original_string)
word_parts = original_string.split('_')
@@ -35,6 +36,10 @@ def ask_worker key,data
end
end
+ def send_object data
+ @going_to_user = data
+ end
+
def start_worker data
@outgoing_data = data
end
@@ -45,7 +50,9 @@ def ask_for_exception type
end
class DummyLogger
- def method_missing method_id,*args; "boy"; end
+ def method_missing method_id,*args;
+ puts *args
+ end
end
logger = DummyLogger.new
@master_worker.debug_logger = logger
@@ -56,14 +63,14 @@ def method_missing method_id,*args; "boy"; end
:type=>:sync_invoke, :arg=>"boy", :worker=>:foo_worker, :worker_method=>"barbar"
}
@master_worker.expects(:method_invoke).with(sync_request).returns(nil)
- @master_worker.receive_data(dump_object(sync_request))
+ @master_worker.receive_data(packet_dump(sync_request))
end
specify "ignore errors while recreating object" do
sync_request = {
:type=>:sync_invoke, :arg=>"boy", :worker=>:foo_worker, :worker_method=>"barbar"
}
- foo = dump_object(sync_request)
+ foo = packet_dump(sync_request)
foo[0] = 'h'
@master_worker.expects(:method_invoke).never
@master_worker.receive_data(foo)
@@ -73,29 +80,32 @@ def method_missing method_id,*args; "boy"; end
b = {
:type=>:async_invoke, :arg=>"boy", :worker=>:foo_worker, :worker_method=>"barbar"
}
- @master_worker.receive_data(dump_object(b))
+
+ @master_worker.expects(:worker_methods).returns(["barbar"])
+ @master_worker.receive_data(packet_dump(b))
@master_worker.outgoing_data.should == {:type=>:request, :data=>{:worker_method=>"barbar", :arg=>"boy"}, :result=>false}
+ @master_worker.going_to_user.should == { :result_flag => "ok" }
@master_worker.key.should == :foo_worker
end
specify "should route sync requests and return results" do
a = {:type=>:sync_invoke, :arg=>"boy", :worker=>:foo_worker, :worker_method=>"barbar"}
- @master_worker.receive_data(dump_object(a))
+ @master_worker.receive_data(packet_dump(a))
@master_worker.outgoing_data.should == {:type=>:request, :data=>{:worker_method=>"barbar", :arg=>"boy"}, :result=>true}
@master_worker.key.should == :foo_worker
end
specify "should route start worker requests" do
d = {:worker_key=>"boy", :type=>:start_worker, :worker=>:foo_worker}
- @master_worker.receive_data(dump_object(d))
+ @master_worker.receive_data(packet_dump(d))
@master_worker.outgoing_data.should == {:type=>:start_worker, :worker_key=>"boy", :worker=>:foo_worker}
end
# FIXME: this test should be further broken down
specify "should run delete worker requests itself" do
e = {:worker_key=>"boy", :type=>:delete_worker, :worker=>:foo_worker}
@master_worker.expects(:delete_drb_worker).returns(nil)
- @master_worker.receive_data(dump_object(e))
+ @master_worker.receive_data(packet_dump(e))
end
specify "should route worker info requests" do
@@ -106,7 +116,7 @@ def method_missing method_id,*args; "boy"; end
t_reactor.expects(:live_workers).returns(live_workers)
@master_worker.expects(:send_object).with({:worker_key=>"boy", :worker=>:foo_worker, :status=>:stopped}).returns(true)
@master_worker.expects(:reactor).returns(t_reactor)
- @master_worker.receive_data(dump_object(g))
+ @master_worker.receive_data(packet_dump(g))
end
specify "should route all_worker_info requests" do
@@ -118,12 +128,12 @@ def method_missing method_id,*args; "boy"; end
@master_worker.expects(:send_object).returns(true)
@master_worker.expects(:reactor).returns(t_reactor)
- @master_worker.receive_data(dump_object(f))
+ @master_worker.receive_data(packet_dump(f))
end
specify "should route worker result requests" do
c = {:type=>:get_result, :worker=>:foo_worker, :job_key=>:start_message}
- @master_worker.receive_data(dump_object(c))
+ @master_worker.receive_data(packet_dump(c))
@master_worker.outgoing_data.should == {:type=>:get_result, :data=>{:job_key=>:start_message}, :result=>true}
end
@@ -135,13 +145,13 @@ def method_missing method_id,*args; "boy"; end
live_workers.expects(:delete).returns(true)
t_reactor.expects(:live_workers).returns(live_workers)
@master_worker.expects(:reactor).returns(t_reactor)
- @master_worker.receive_data(dump_object(c))
+ @master_worker.receive_data(packet_dump(c))
end
specify "should ignore generic exceptions while fetching results" do
c = {:type=>:get_result, :worker=>:foo_worker, :job_key=>:start_message}
@master_worker.ask_for_exception(:generic)
- @master_worker.receive_data(dump_object(c))
+ @master_worker.receive_data(packet_dump(c))
@master_worker.outgoing_data.should == nil
end
end
View
30 test/server/test_meta_worker.rb
@@ -3,11 +3,12 @@
require "chronic"
context "A Meta Worker should" do
- def dump_object data
- t = Marshal.dump(data)
- t.length.to_s.rjust(9,'0') + t
+ module Kernel
+ def packet_dump data
+ t = Marshal.dump(data)
+ t.length.to_s.rjust(9,'0') + t
+ end
end
-
setup do
options = {:schedules =>
{
@@ -64,7 +65,7 @@ def ivar(var)
specify "should invoke async tasks without sending results" do
a = {:data=>{:worker_method=>"who", :arg=>"rails",:job_key => "lol"}, :type=>:request, :result=>false, :client_signature=>9}
@meta_worker.expects(:who).with("rails").returns(nil)
- @meta_worker.receive_internal_data(dump_object(a))
+ @meta_worker.receive_internal_data(packet_dump(a))
Thread.current[:job_key].should == "lol"
end
@@ -75,8 +76,8 @@ def baz args
end
end
b = {:data=>{:worker_method=>"baz", :arg=>"rails"}, :type=>:request, :result=>true, :client_signature=>9}
- @meta_worker.expects(:send_data).with({:data=>"hello : rails", :type=>:response, :result=>true, :client_signature=>9}).returns("hello : rails")
- @meta_worker.receive_internal_data(dump_object(b))
+ @meta_worker.expects(:send_data).with({:data=>"hello : rails", :type=>:response, :result=>true, :client_signature=>9, :result_flag => "ok"}).returns("hello : rails")
+ @meta_worker.receive_internal_data(packet_dump(b))
Thread.current[:job_key].should == nil
end
@@ -90,7 +91,7 @@ def send_data data
b = {:data=> {:worker_method=>"baz", :arg => { :name => "bdrb",:age => 10} }, :type=>:request, :result=>true, :client_signature=>9 }
# @meta_worker.expects(:send_data).with({:data=>"hello : rails", :type=>:response, :result=>true, :client_signature=>9}).returns("hello : rails")
@meta_worker.expects(:baz).with({ :name => "bdrb",:age => 10}).returns("foo")
- @meta_worker.receive_internal_data(dump_object(b))
+ @meta_worker.receive_internal_data(packet_dump(b))
@meta_worker.outgoing_data[:data].should == "foo"
Thread.current[:job_key].should == nil
end
@@ -104,7 +105,7 @@ def send_data data
end
@meta_worker.cache[:start_message] = "helloworld"
c = {:data=>{:job_key=>:start_message}, :type=>:get_result, :result=>true, :client_signature=>9}
- @meta_worker.receive_internal_data(dump_object(c))
+ @meta_worker.receive_internal_data(packet_dump(c))
@meta_worker.t_result[:data].should == "helloworld"
end
@@ -114,15 +115,14 @@ def baz args
proc { "boy"}
end
def send_data input
- dump_object(input)
+ packet_dump(input)
end
end
b = {:data=>{:worker_method=>"baz", :arg=>"rails"}, :type=>:request, :result=>true, :client_signature=>9}
- a = @meta_worker.receive_internal_data(dump_object(b))
- a.should == nil
+ a = @meta_worker.receive_internal_data(packet_dump(b))
+ p a
Thread.current[:job_key].should == nil
end
-
end
context "For unix schedulers" do
@@ -260,7 +260,7 @@ def ivar(var)
specify "should run enqueued tasks with arguments if they are there in the queue" do
@meta_worker = QueueWorker.start_worker
mocked_task = mock()
- mocked_task.expects(:worker_method).returns(:barbar).times(3)
+ mocked_task.expects(:worker_method).returns(:barbar).times(2)
mocked_task.expects(:args).returns(Marshal.dump("hello"))
mocked_task.expects(:[]).returns(1).times(2)
@meta_worker.expects(:barbar).with("hello").returns(true)
@@ -272,7 +272,7 @@ def ivar(var)
@meta_worker = QueueWorker.start_worker
mocked_task = mock()
mocked_task.expects(:[]).returns(1).times(2)
- mocked_task.expects(:worker_method).returns(:barbar).times(3)
+ mocked_task.expects(:worker_method).returns(:barbar).times(2)
mocked_task.expects(:args).returns(nil)
@meta_worker.expects(:barbar)
BdrbJobQueue.expects(:find_next).with("queue_worker").returns(mocked_task)

0 comments on commit 2266836

Please sign in to comment.