Skip to content

Commit ceba333

Browse files
author
Steve Newell
committed
update/fix specs
1 parent 3557e4b commit ceba333

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

spec/lib/protobuf/rpc/connectors/base_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@
187187
shared_examples "a ConnectorDisposition" do |meth, cb, *args|
188188

189189
it "calls #complete before exit" do
190-
subject.stats = double("Object", :stop => true)
190+
subject.stats = ::Protobuf::Rpc::Stat.new(:stop => true)
191191

192192
expect(subject).to receive(:complete)
193193
subject.method(meth).call(*args)
194194
end
195195

196196
it "calls the #{cb} callback when provided" do
197-
stats = double("Object")
197+
stats = ::Protobuf::Rpc::Stat.new
198198
allow(stats).to receive(:stop).and_return(true)
199199
subject.stats = stats
200200
some_cb = double("Object")
@@ -205,7 +205,7 @@
205205
end
206206

207207
it "calls the complete callback when provided" do
208-
stats = double("Object")
208+
stats = ::Protobuf::Rpc::Stat.new
209209
allow(stats).to receive(:stop).and_return(true)
210210
subject.stats = stats
211211
comp_cb = double("Object")
@@ -217,8 +217,8 @@
217217

218218
end
219219

220-
it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message")
221-
it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message")
220+
it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", :RPC_ERROR, "message")
221+
it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", :RPC_ERROR, "message")
222222
it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response")
223223
it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response")
224224
it_behaves_like("a ConnectorDisposition", :complete, "complete_cb")

spec/lib/protobuf/rpc/stat_spec.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
::Timecop.freeze(1.62.seconds.from_now) do
3535
stats.stop
36-
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}"
36+
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - OK - #{::Time.now.iso8601}"
3737
end
3838
end
3939
end
@@ -44,7 +44,7 @@
4444
stats.client = 'myserver1'
4545
stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars))
4646
stats.request_size = 43
47-
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-"
47+
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/- - OK"
4848
end
4949
end
5050
end
@@ -61,20 +61,39 @@
6161

6262
::Timecop.freeze(0.832.seconds.from_now) do
6363
stats.stop
64-
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}"
64+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - OK - #{::Time.now.iso8601}"
6565
end
6666

6767
end
6868
end
6969

70+
describe 'error log' do
71+
it 'resolves error to a string' do
72+
::Timecop.freeze(10.minutes.ago) do
73+
stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
74+
stats.server = ['30000', 'myserver1.myhost.com']
75+
stats.service = 'Foo::BarService'
76+
stats.status = ::Protobuf::Socketrpc::ErrorReason::RPC_ERROR
77+
stats.method_name = 'find_bars'
78+
stats.request_size = 37
79+
stats.response_size = 12345
80+
81+
::Timecop.freeze(0.832.seconds.from_now) do
82+
stats.stop
83+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - RPC_ERROR - #{::Time.now.iso8601}"
84+
end
85+
end
86+
end
87+
end
88+
7089
context 'when request is still running' do
7190
it 'omits response size, duration, and timestamp' do
7291
stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
7392
stats.server = ['30000', 'myserver1.myhost.com']
7493
stats.service = 'Foo::BarService'
7594
stats.method_name = 'find_bars'
7695
stats.request_size = 37
77-
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-"
96+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/- - OK"
7897
end
7998
end
8099
end

0 commit comments

Comments
 (0)