require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/test_server'
require 'drb'

describe "DRb.start_service" do
  before :all do
    port = 9001 + (Process.pid & 7)
    @url = "druby://localhost:#{port}"
  end

  it "should run a basic remote call" do    
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
    server = DRb.start_service(@url, TestServer.new)
    DRb.current_server.should == server
    obj = DRbObject.new(nil, @url)
    obj.add(1,2,3).should == 6
    DRb.stop_service
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
  end

  it "should run a basic remote call passing a block" do
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
    server = DRb.start_service(@url, TestServer.new)
    DRb.current_server.should == server
    obj = DRbObject.new(nil, @url)
    obj.add_yield(2) do |i|
      i.should == 2
      i+1
    end.should == 4
    DRb.stop_service
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
  end
end

require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/test_server'
require 'drb'

describe "DRb.start_service" do
  it "should run a basic remote call" do    
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
    server = DRb.start_service('druby://localhost:9001', TestServer.new)
    DRb.current_server.should == server
    obj = DRbObject.new(nil, 'druby://localhost:9001')
    obj.add(1,2,3).should == 6
    DRb.stop_service
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
  end

  it "should run a basic remote call passing a block" do
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
    server = DRb.start_service('druby://localhost:9001', TestServer.new)
    DRb.current_server.should == server
    obj = DRbObject.new(nil, 'druby://localhost:9001')
    obj.add_yield(2) do |i|
      i.should == 2
      i+1
    end.should == 4
    DRb.stop_service
    lambda { DRb.current_server }.should raise_error(DRb::DRbServerNotFound)
  end
end

Revert "Made DRb spec depend partially on PID so multiple runs don't clash."
Revert "Made DRb spec depend partially on PID so multiple runs don't clash."

The spec is designed for sane behavior, if Rubinius or the
implementation of DRb is causing problems then they should be
fixed, not the spec in this case.  Fixing the spec will only
hide the bug.

See http://jira.codehaus.org/browse/JRUBY-2347 for more commentary on the problem.

This reverts commit f89bd8c6c425c9d9bcc3e589b8d3b05ce3ccbced.
