Git Product home page Git Product logo

Comments (5)

mensfeld avatar mensfeld commented on June 1, 2024

Note to self: this will require execution of the whole strategy around dispatch.

from karafka-testing.

Vadimvf avatar Vadimvf commented on June 1, 2024

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.

mensfeld avatar mensfeld commented on June 1, 2024

@Vadimvf I pushed the change you made. It's exactly what was needed to address this.

from karafka-testing.

mensfeld avatar mensfeld commented on June 1, 2024

@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.

mensfeld avatar mensfeld commented on June 1, 2024

2.0.9 has been released

from karafka-testing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.