Test::Unit and drb

D

Damphyr

Anybody have any tips to share about unit testing code that uses drb?

My problem is, I can test all the the logic in smaller chunks, but as
soon as I integrate everyhting and have code in place that verifies and
recovers from connection errors I need to at least establish that drb
connection.

How would I go about doing this in a unit test environment?
Getting a mock drb server in a thread and launching it in setup seems
too clunky.
Any brilliant ideas?
Cheers,
V.-
 
F

Farrel Lifson

Anybody have any tips to share about unit testing code that uses drb?

My problem is, I can test all the the logic in smaller chunks, but as
soon as I integrate everyhting and have code in place that verifies and
recovers from connection errors I need to at least establish that drb
connection.

How would I go about doing this in a unit test environment?
Getting a mock drb server in a thread and launching it in setup seems
too clunky.
Any brilliant ideas?
Cheers,
V.-

This is how I've done it though if anyone has better solutions I'd be
glad to hear them:

require 'drb'
require 'test/unit'

class Counter
def initialize;@counter = 0;end
def count;@counter+=1;end

def self.start
DRb.start_service("druby://localhost:9000",self.new)
end

def stop
DRb.stop_service
end
end

class TC_Counter < Test::Unit::TestCase
def setup
@t = Thread.new do
Counter.start
end
@counter = DRbObject.new_with_uri("druby://localhost:9000")
end

def teardown
@counter.stop
@t.exit
end

def test_count
assert_equal(1,@counter.count)
assert_equal(2,@counter.count)
assert_equal(3,@counter.count)
end
end
 
E

Eric Hodel

Anybody have any tips to share about unit testing code that uses drb?

My problem is, I can test all the the logic in smaller chunks, but
as soon as I integrate everyhting and have code in place that
verifies and recovers from connection errors I need to at least
establish that drb connection.

How is multiprocess operation (DRb dispatched) different from
multithreaded operation (method calls) for your program?
 
D

Damphyr

Eric said:
How is multiprocess operation (DRb dispatched) different from
multithreaded operation (method calls) for your program?
It's not, apart from the fact that the drb server might just not be
there, so I need to recover from network errors in some way.
I am testing everything before putting it together and I am testing
without a drb connection.
Thing is in one case I make two or three calls over drb and at the
moment I can only test what happens when the first call fails, but not
what happens when the connection goes away in between calls.
The whole scenario is more of an integration test and fitting it into
Test::Unit is a bit of a push.
Cheers,
V.-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,944
Members
47,491
Latest member
mohitk

Latest Threads

Top