Project

General

Profile

Bug #2718 ยป drb_test_case.rb

rhythmx (Sean Bradly), 02/07/2010 03:52 AM

 
1
require 'drb'
2

    
3
# pass anything as an arg to make this script fail
4
borked_mode = ARGV.shift 
5

    
6
# The RPC Server Class
7
class Foo
8
	def a
9
		"AAAA"
10
	end
11
	def b
12
		"BBBB"
13
	end
14
	def c
15
		"CCCC"
16
	end
17
end
18

    
19
# Save all the child pids
20
pids = []
21

    
22
# Run the RPC Server in a seperate process
23
pids << Kernel.fork do
24
	DRb.start_service("druby://127.0.0.1:13370",Foo.new)
25
	sleep # until process gets killed
26
end
27
sleep(1)
28

    
29
# If the parent process calls any remote method at all, the child PIDs get invalid data
30
client = DRbObject.new_with_uri("druby://127.0.0.1:13370")
31

    
32
# Comment this line and this script works, otherwise data gets mixed up.
33
client.c if borked_mode
34

    
35
# Startup 10 child processes that call 'a' on the rpc server
36
10.times do
37
	pids << Kernel.fork do 
38
		require 'drb'
39
		begin
40
			client = DRbObject.new_with_uri("druby://127.0.0.1:13370")
41
			while true
42
				res = client.a
43
				if res !~ /AAAA/
44
					puts "A BAD RESULT (#{res.inspect})" 
45
				else
46
					puts "a ok"
47
				end
48
				sleep(0.2)
49
			end
50
		rescue
51
			puts "a exiting"
52
		end
53
	end
54
end
55

    
56
# Startup 10 child processes that call 'b' on the rpc server
57
10.times do
58
	pids << Kernel.fork do 
59
		require 'drb'
60
		begin
61
			client = DRbObject.new_with_uri("druby://127.0.0.1:13370") 
62
			while true
63
				res = client.b
64
				if res !~ /BBBB/
65
					puts "B BAD RESULT (#{res.inspect})"
66
				else
67
					puts "b ok"
68
				end
69
				sleep(0.2)
70
			end
71
		rescue
72
			puts "b exiting"
73
		end
74
	end
75
end
76

    
77
sleep(5)
78

    
79
pids.each do |p|
80
	Process.kill('KILL',p) rescue nil
81
	Process.waitpid(p,Process::WNOHANG)
82
end
83

    
84
exit