redis-rpc 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0e33433f97014ca9e292fc721e48271ff83ec58
4
- data.tar.gz: ea4b5130c90bbb44a926a3e88e5be2d46adb0189
3
+ metadata.gz: d608b2b9dcd7726ea7cf1bd599a2660c14bdcb61
4
+ data.tar.gz: b092789f2589d8a295e5d107eec22fded3b0d99a
5
5
  SHA512:
6
- metadata.gz: f08569b5d4f2186c956efd1bb195adc56577269551c823645d0affad65c309a9efe1808b59d125e7254580ed5deb4ab236d2c8c22a40c86782b89b862c94efa2
7
- data.tar.gz: fa9ebbd23ebf9912181f1a09fe7a241892be87d1dc985f2757a640ca14770506248db2c2f87f6fa28f6a3c702f7250140a25092c9baea0698bd75575479b88d4
6
+ metadata.gz: ec293260273ea94bda89e29b7d0529446de63e2f1ed0fd0ecc29dbcdfbe02e74c003a1627ee7622da45653ed6008a1d9ece7317d99fbbb84e5906a1aa892b1a4
7
+ data.tar.gz: 01b70312c304a9a27b98356aa0fcfd86d1e3518ad4d03d9a7d514918de618e41969b09bf8fbee8ea844e178cc04ddf2d217ff6e5946b6586891e4ab734cc953d
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-rpc (1.1.0)
4
+ redis-rpc (1.2.0)
5
5
  multi_json (~> 1.3)
6
6
  redis
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
+ byebug (10.0.2)
11
12
  diff-lcs (1.3)
12
13
  multi_json (1.13.1)
13
14
  rake (0.9.2)
@@ -31,6 +32,7 @@ PLATFORMS
31
32
 
32
33
  DEPENDENCIES
33
34
  bundler
35
+ byebug
34
36
  rake
35
37
  redis-rpc!
36
38
  rspec
@@ -48,13 +48,23 @@ module RedisRpc
48
48
  end
49
49
 
50
50
  alias :send! :send
51
+
52
+ def get_timeout_at
53
+ # allow mock to manipulate timeout to verify safety behavior
54
+ Time.now.to_i + @timeout + 60
55
+ end
56
+
51
57
  def send( method_name, *args)
52
58
  raise MalformedRequestException, 'block not allowed over RPC' if block_given?
53
59
 
54
60
  # request setup
55
61
  function_call = {'name' => method_name.to_s, 'args' => args}
56
62
  response_queue = @message_queue + ':rpc:' + rand_string
57
- rpc_request = {'function_call' => function_call, 'response_queue' => response_queue}
63
+ rpc_request = {
64
+ 'function_call' => function_call, 'response_queue' => response_queue,
65
+ 'timeout_at' => get_timeout_at,
66
+ }
67
+
58
68
  rpc_raw_request = MultiJson.dump rpc_request
59
69
 
60
70
  # transport
@@ -121,9 +131,17 @@ module RedisRpc
121
131
 
122
132
  # request execution
123
133
  begin
134
+ if rpc_request['timeout_at'].nil?
135
+ raise "Unsafe RPC call: timeout_at not specified"
136
+ end
137
+
138
+ if rpc_request['timeout_at'] < Time.now.to_i
139
+ raise "Expired RPC call. timeout_at = #{rpc_request['timeout_at']}. Time.now = #{Time.now.to_i}"
140
+ end
141
+
124
142
  return_value = @local_object.send( function_call['name'].to_sym, *function_call['args'] )
125
143
  rpc_response = {'return_value' => return_value}
126
- rescue Object => err
144
+ rescue Exception => err
127
145
  rpc_response = {'exception' => err.to_s, 'backtrace' => err.backtrace}
128
146
  end
129
147
 
@@ -142,7 +160,7 @@ module RedisRpc
142
160
 
143
161
  def timeout
144
162
  @timeout or
145
- $REDISRPC_SERVER_TIMEOUT or
163
+ $REDISRPC_SERVER_TIMEOUT or
146
164
  0
147
165
  end
148
166
  end
@@ -1,3 +1,3 @@
1
1
  module RedisRpc
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -42,4 +42,5 @@ Gem::Specification.new do |s|
42
42
  s.add_development_dependency 'bundler'
43
43
  s.add_development_dependency 'rake'
44
44
  s.add_development_dependency 'rspec'
45
+ s.add_development_dependency 'byebug'
45
46
  end
@@ -2,40 +2,57 @@ require File.expand_path( '../spec_helper.rb', __FILE__ )
2
2
  require File.expand_path( '../../examples/calc.rb', __FILE__ )
3
3
 
4
4
  describe Calculator do
5
- [true,false].each do |over_redisrpc|
6
- context "when run #{( over_redisrpc ? 'over redisrpc' : 'locally')}" do
7
-
8
- if( over_redisrpc )
9
- let(:rpc_server_builder){ lambda{ RedisRpc::Server.new( Redis.new($REDIS_CONFIG), 'calc', Calculator.new ) } }
10
- before(:each) do
11
- @server_pid = fork{ rpc_server_builder.call.run }
12
- end
13
- after(:each){ Process.kill(9, @server_pid); rpc_server_builder.call.flush_queue! }
14
- let(:calculator){ RedisRpc::Client.new( $REDIS,'calc', 1) }
15
- else
16
- let(:calculator){ Calculator.new }
17
- end
5
+ context "locally" do
6
+ let(:calculator){ Calculator.new }
18
7
 
19
- it 'should calculate' do
20
- calculator.val.should == 0.0
21
- calculator.add(3).should == 3.0
22
- calculator.sub(2).should == 1.0
23
- calculator.mul(14).should == 14.0
24
- calculator.div(7).should == 2.0
25
- calculator.val.should == 2.0
26
- calculator.clr.should == 0.0
27
- calculator.val.should == 0.0
28
- end
8
+ it 'should calculate' do
9
+ calculator.val.should == 0.0
10
+ calculator.add(3).should == 3.0
11
+ calculator.sub(2).should == 1.0
12
+ calculator.mul(14).should == 14.0
13
+ calculator.div(7).should == 2.0
14
+ calculator.val.should == 2.0
15
+ calculator.clr.should == 0.0
16
+ calculator.val.should == 0.0
17
+ end
29
18
 
30
- it 'should raise when missing method is called' do
31
- expect{ calculator.a_missing_method }.to raise_error(
32
- over_redisrpc ? RedisRpc::RemoteException : NoMethodError
33
- )
34
- end
19
+ it 'should raise when missing method is called' do
20
+ expect{ calculator.a_missing_method }.to raise_error(NoMethodError)
21
+ end
22
+ end
23
+
24
+ context "over rpc" do
25
+ let(:rpc_server_builder){ lambda{ RedisRpc::Server.new( Redis.new($REDIS_CONFIG), 'calc', Calculator.new ) } }
26
+ before(:each) do
27
+ @server_pid = fork{ rpc_server_builder.call.run }
28
+ end
29
+ after(:each){ Process.kill(9, @server_pid); rpc_server_builder.call.flush_queue! }
30
+ let(:calculator){ RedisRpc::Client.new( $REDIS,'calc', 1) }
35
31
 
36
- it 'should raise timeout when execution expires' do
37
- expect{ calculator.send(:sleep,2) }.to raise_error RedisRpc::TimeoutException
38
- end if over_redisrpc
32
+ it 'should calculate' do
33
+ calculator.val.should == 0.0
34
+ calculator.add(3).should == 3.0
35
+ calculator.sub(2).should == 1.0
36
+ calculator.mul(14).should == 14.0
37
+ calculator.div(7).should == 2.0
38
+ calculator.val.should == 2.0
39
+ calculator.clr.should == 0.0
40
+ calculator.val.should == 0.0
41
+ end
42
+
43
+ it 'should raise when missing method is called' do
44
+ expect{ calculator.a_missing_method }.to raise_error(RedisRpc::RemoteException)
45
+ end
46
+
47
+ it 'should raise timeout when execution expires' do
48
+ expect{ calculator.send(:sleep,2) }.to raise_error RedisRpc::TimeoutException
49
+ end
50
+
51
+ context "the request is executed late" do
52
+ it "won't be executed" do
53
+ allow(calculator).to receive(:get_timeout_at).and_return(Time.now.to_i - 1)
54
+ expect { calculator.val }.to raise_error(RedisRpc::RemoteException, /Expired RPC call/)
55
+ end
39
56
  end
40
57
  end
41
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phuong Nguyen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-20 00:00:00.000000000 Z
12
+ date: 2018-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: byebug
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  description: |2
85
99
  RedisRpc is the easiest to use RPC library in the world. (No small claim!).
86
100
  This version is a repackage that only has Ruby implementation.