spec/replication_runner_spec.rb in rubyrep-1.0.7 vs spec/replication_runner_spec.rb in rubyrep-1.0.8

- old
+ new

@@ -2,10 +2,11 @@ include RR describe ReplicationRunner do before(:each) do + Initializer.configuration = standard_config end it "should register itself with CommandRunner" do CommandRunner.commands['replicate'][:command].should == ReplicationRunner CommandRunner.commands['replicate'][:description].should be_an_instance_of(String) @@ -164,9 +165,39 @@ $stderr.string.should =~ /Exception caught.*refresh failed/ $stderr.string.should =~ /replication_runner.rb:[0-9]+:in/ ensure $stderr = org_stderr end + end + + it "execute_once should not clean up if successful" do + runner = ReplicationRunner.new + session = Session.new + runner.instance_variable_set(:@session, session) + + runner.execute_once + runner.instance_variable_get(:@session).should == session + end + + it "execute_once should clean up after failed replication runs" do + runner = ReplicationRunner.new + session = Session.new + runner.instance_variable_set(:@session, session) + + session.should_receive(:refresh).and_raise('bla') + lambda {runner.execute_once}.should raise_error('bla') + runner.instance_variable_get(:@session).should be_nil + end + + it "execute_once should raise exception if replication run times out" do + session = Session.new + runner = ReplicationRunner.new + runner.stub!(:session).and_return(session) + terminated = mock("terminated") + terminated.stub!(:terminated?).and_return(true) + TaskSweeper.stub!(:timeout).and_return(terminated) + + lambda {runner.execute_once}.should raise_error(/timed out/) end it "execute should start the replication" do config = deep_copy(standard_config) config.options[:committer] = :buffered_commit \ No newline at end of file