Comments (5)
Note to self: this will require execution of the whole strategy around dispatch.
from karafka-testing.
Posting some additional context - when testing a consumer that:
- has DLQ enabled
- uses the manual dispatched api, aka
#dispatch_to_dlq
- sends an invalid message within a spec
You'll hit a NoMethod
error as the consumer created isn't aware to use the dlq strategy and doesn't implement dispatch_to_dlq.
I was able to work around this by patching in the strategy_selector code used in lib/karafka/processing/executor.rb#L117 to the testing library lib/karafka/testing/rspec/helpers.rb
:
def _karafka_build_consumer_for(topic)
coordinators = Karafka::Processing::CoordinatorsBuffer.new
consumer = described_class.new
consumer.topic = topic
consumer.producer = Karafka::App.producer
consumer.client = _karafka_consumer_client
consumer.coordinator = coordinators.find_or_create(topic.name, 0)
consumer.coordinator.seek_offset = 0
-> # new addition
-> strategy = ::Karafka::App.config.internal.processing.strategy_selector.find(topic)
-> consumer.singleton_class.include(strategy)
consumer
end
related diff: https://github.com/Vadimvf/karafka-testing/pull/1/files
This also allows for using the existing helper to check if the manual dlq dispatch worked.
Debug output when checking produced messages:
karafka.produced_messages.last[:topic]
=> "my_topic.dead_messages"
Note - I don't believe this works with the consumer lifecycle beyond that, e.g. testing consumer.consume
with manual dispatch works, but consumer.on_consume
(to include the rescue logic needed for unhandled errors) isn't addressed.
I haven't had a moment to look into that yet but posting so I don't forget above for now.
from karafka-testing.
@Vadimvf I pushed the change you made. It's exactly what was needed to address this.
from karafka-testing.
@Vadimvf @ajs-codes would you mind testing the master branch? I added your suggested code.
I don't believe this works with the consumer lifecycle beyond that, e.g. testing consumer.consume with manual dispatch works, but consumer.on_consume (to include the rescue logic needed for unhandled errors) isn't addressed.
Why?
from karafka-testing.
2.0.9 has been released
from karafka-testing.
Related Issues (20)
- Configuration testing HOT 10
- `certs/cert_chain.pem` permissions are wrong in the gem from rubygems HOT 3
- Do not use `described_class` to build consumer but instead use routing topic reference
- Dependency Dashboard
- have_enqueued_job rspec matcher does not work with :karafka ActiveJob queue_adapter HOT 3
- Retire the client stubs and replace them with alternative client after WaterDrop `2.6.0` release HOT 2
- NameError: uninitialized constant WaterDrop::Producer::DummyClient HOT 4
- Add support for client commit_offsets and commit_offsets! stubs
- Headers are not accumulated in the bufferred rspec tracker HOT 1
- Expand dummy client API with `#seek`
- karafka-testing 2.1.2 "consumer_for" helper, passed consumer_group not working. HOT 1
- Expand dummy api with `#used?`
- Make sure dummy producer supports transactions HOT 1
- Support for testing around pattern matching in topic to consumer mapping HOT 3
- Same CG multiplexing topic builder fails with TopicInManyConsumerGroupsError
- Detect lack of configuration of Karafka prior to mocking
- Error in v2.3.1: undefined method `ensure_karafka_initialized!' for Karafka::Testing:Module HOT 4
- Incompatibility of Deserializer with Testing
- Multi SG consumer group with high multiplexing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karafka-testing.