Skip to content

Commit

Permalink
Merge pull request #342 from lairen/docker-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deepredsky authored Oct 6, 2023
2 parents 792007a + 2ef014c commit ebdb2e7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM circleci/ruby:2.7.2
FROM cimg/ruby:2.7.8

RUN sudo apt-get update
RUN sudo apt-get install docker
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,12 @@ The integration tests run against a Kafka instance that is not automatically sta
### Running RSpec within Docker
There can be behavioural inconsistencies between running the specs on your machine, and in the CI pipeline. Due to this, there is now a Dockerfile included in the project, which is based on the CircleCI ruby 2.7.2 image. This could easily be extended with more Dockerfiles to cover different Ruby versions if desired. In order to run the specs via Docker:
There can be behavioural inconsistencies between running the specs on your machine, and in the CI pipeline. Due to this, there is now a Dockerfile included in the project, which is based on the CircleCI ruby 2.7.8 image. This could easily be extended with more Dockerfiles to cover different Ruby versions if desired. In order to run the specs via Docker:
- Uncomment the `tests` service from the docker-compose.yml
- Bring up the stack with `docker-compose up -d`
- Execute the entire suite with `docker-compose run --rm tests rspec`
- Execute a single spec or directory with `docker-compose run --rm tests rspec spec/integration/consumer_spec.rb`
- Execute the entire suite with `docker-compose run --rm tests bundle exec rspec`
- Execute a single spec or directory with `docker-compose run --rm tests bundle exec rspec spec/integration/consumer_spec.rb`
Please note - your code directory is mounted as a volume, so you can make code changes without needing to rebuild
Expand Down
5 changes: 5 additions & 0 deletions lib/racecar/consumer_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def commit_rescue_no_offset(consumer)
def rdkafka_config(subscription)
# https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
config = {
# Manually store offset after messages have been processed successfully
# to avoid marking failed messages as committed. The call just updates
# a value within librdkafka and is asynchronously written to proper
# storage through auto commits.
"enable.auto.offset.store" => false,
"auto.commit.interval.ms" => @config.offset_commit_interval * 1000,
"auto.offset.reset" => subscription.start_from_beginning ? "earliest" : "largest",
"bootstrap.servers" => @config.brokers.join(","),
Expand Down
7 changes: 1 addition & 6 deletions lib/racecar/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run
end
ensure
producer.close
Racecar::Datadog.close if Object.const_defined?("Racecar::Datadog")
Racecar::Datadog.close if config.datadog_enabled
@instrumenter.instrument("shut_down", instrumentation_payload || {})
end

Expand Down Expand Up @@ -131,11 +131,6 @@ def process_method

def consumer
@consumer ||= begin
# Manually store offset after messages have been processed successfully
# to avoid marking failed messages as committed. The call just updates
# a value within librdkafka and is asynchronously written to proper
# storage through auto commits.
config.consumer << "enable.auto.offset.store=false"
ConsumerSet.new(config, logger, @instrumenter)
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@

describe "#load_env" do
it "sets the brokers from RACECAR_BROKERS" do
ENV["RACECAR_BROKERS"] = "hansel,gretel"

expect(config.brokers).to eq ["hansel", "gretel"]
with_env("RACECAR_BROKERS", "hansel,gretel") do
expect(config.brokers).to eq ["hansel", "gretel"]
end
end

it "sets the client id from RACECAR_CLIENT_ID" do
Expand All @@ -92,15 +92,15 @@
end

it "sets the offset commit interval from RACECAR_OFFSET_COMMIT_INTERVAL" do
ENV["RACECAR_OFFSET_COMMIT_INTERVAL"] = "45"

expect(config.offset_commit_interval).to eq 45
with_env("RACECAR_OFFSET_COMMIT_INTERVAL", '45') do
expect(config.offset_commit_interval).to eq 45
end
end

it "sets the heartbeat interval from RACECAR_HEARTBEAT_INTERVAL" do
ENV["RACECAR_HEARTBEAT_INTERVAL"] = "45"

expect(config.heartbeat_interval).to eq 45
with_env("RACECAR_HEARTBEAT_INTERVAL", "45") do
expect(config.heartbeat_interval).to eq 45
end
end
end

Expand Down
5 changes: 3 additions & 2 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ def process_batch(batch, hello); end

context "when DataDog metrics are disabled" do
before do
allow(Object).to receive(:const_defined?).with("Racecar::Datadog").and_return(false)
stub_const("Racecar::Datadog", datadog)
config.datadog_enabled = false
end

it "does not close Datadog::Statsd instance" do
Expand All @@ -752,7 +753,7 @@ def process_batch(batch, hello); end
context "when DataDog metrics are enabled" do
before do
stub_const("Racecar::Datadog", datadog)
allow(Object).to receive(:const_defined?).with("Racecar::Datadog").and_return(true)
config.datadog_enabled = true
end

it "closes Datadog::Statsd instance" do
Expand Down

0 comments on commit ebdb2e7

Please sign in to comment.