Skip to content

Commit 1c26554

Browse files
authored
Fix spec setup (#189)
Fix spec setup This fixes some test setup that used mock but ended up not covering some inner dependencies. The mocks were changed back to real object. This also removes some unused variables shown as warning by the linter.
1 parent 76e6221 commit 1c26554

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

lib/rdkafka/admin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def create_topic(topic_name, partition_count, replication_factor, topic_config={
9090
admin_options_ptr,
9191
queue_ptr
9292
)
93-
rescue Exception => err
93+
rescue Exception
9494
CreateTopicHandle.remove(create_topic_handle.to_ptr.address)
9595
raise
9696
ensure
@@ -140,7 +140,7 @@ def delete_topic(topic_name)
140140
admin_options_ptr,
141141
queue_ptr
142142
)
143-
rescue Exception => err
143+
rescue Exception
144144
DeleteTopicHandle.remove(delete_topic_handle.to_ptr.address)
145145
raise
146146
ensure

spec/rdkafka/consumer_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def send_one_message(val)
241241

242242
it "should return the assignment when subscribed" do
243243
# Make sure there's a message
244-
report = producer.produce(
244+
producer.produce(
245245
topic: "consume_test_topic",
246246
payload: "payload 1",
247247
key: "key 1",
@@ -272,7 +272,7 @@ def send_one_message(val)
272272
it "should close a consumer" do
273273
consumer.subscribe("consume_test_topic")
274274
100.times do |i|
275-
report = producer.produce(
275+
producer.produce(
276276
topic: "consume_test_topic",
277277
payload: "payload #{i}",
278278
key: "key #{i}",
@@ -289,7 +289,7 @@ def send_one_message(val)
289289
describe "#commit, #committed and #store_offset" do
290290
# Make sure there's a stored offset
291291
let!(:report) do
292-
report = producer.produce(
292+
producer.produce(
293293
topic: "consume_test_topic",
294294
payload: "payload 1",
295295
key: "key 1",
@@ -831,7 +831,6 @@ def new_message
831831
)
832832
consumer = config.consumer
833833
consumer.subscribe(topic_name)
834-
loop_count = 0
835834
batches_yielded = []
836835
exceptions_yielded = []
837836
each_batch_iterations = 0
@@ -875,7 +874,6 @@ def new_message
875874
)
876875
consumer = config.consumer
877876
consumer.subscribe(topic_name)
878-
loop_count = 0
879877
batches_yielded = []
880878
exceptions_yielded = []
881879
each_batch_iterations = 0

spec/rdkafka/producer/client_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
require "spec_helper"
22

33
describe Rdkafka::Producer::Client do
4-
let(:native) { double }
4+
let(:config) { rdkafka_producer_config }
5+
let(:native) { config.send(:native_kafka, config.send(:native_config), :rd_kafka_producer) }
56
let(:closing) { false }
67
let(:thread) { double(Thread) }
78

89
subject(:client) { described_class.new(native) }
910

1011
before do
11-
allow(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(native, 250)
12-
allow(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(native).and_return(0)
12+
allow(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(instance_of(FFI::Pointer), 250).and_call_original
13+
allow(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(instance_of(FFI::Pointer)).and_return(0).and_call_original
1314
allow(Rdkafka::Bindings).to receive(:rd_kafka_destroy)
1415
allow(Thread).to receive(:new).and_return(thread)
1516

@@ -41,7 +42,7 @@
4142

4243
it "polls the native with default 250ms timeout" do
4344
polling_loop_expects do
44-
expect(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(native, 250)
45+
expect(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(instance_of(FFI::Pointer), 250)
4546
end
4647
end
4748

spec/rdkafka/producer_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,9 @@ def call(report)
376376
end
377377
end
378378

379-
it "should produce a message in a forked process" do
379+
it "should produce a message in a forked process", skip: defined?(JRUBY_VERSION) && "Kernel#fork is not available" do
380380
# Fork, produce a message, send the report over a pipe and
381381
# wait for and check the message in the main process.
382-
383-
# Kernel#fork is not available in JRuby
384-
skip if defined?(JRUBY_VERSION)
385-
386382
reader, writer = IO.pipe
387383

388384
fork do

0 commit comments

Comments
 (0)