hutch icon indicating copy to clipboard operation
hutch copied to clipboard

Integration specs

Open hmarr opened this issue 12 years ago • 8 comments

Write some integration specs that test the whole process of receiving a message from RabbitMQ, and taking action in a consumer.

hmarr avatar Jan 23 '13 17:01 hmarr

Hi Harry,

Is there any docs or even just a basic example on how to do this.

Really trying to test my consumers but unsure best approach.

I use Sidekiq as well and there is a

Sidekiq::Testing.fake!

Is there anything similar or a pattern I can follow to get some solid testing going?

Cheers,

Luke

lukebyrne avatar Apr 18 '14 10:04 lukebyrne

@lukebyrne no. It's straightforward to connect and publish messages but consumer and config loading may need additional public API methods for convenience.

I'm not sure "fake" implementations count for integration testing, by the way. Having RabbitMQ running locally is not hard.

michaelklishin avatar Apr 18 '14 10:04 michaelklishin

@michaelklishin got any suggestions of how to spin up a hutch consumer from a spec_helper.rb

Here is a gist of a consumer and a consumer_spec I have written up.

Just not sure how I would actually get the test suite to spin up a Hutch like so

consumer: bundle exec hutch --require screenings/hutch_consumers.rb

to flush the message through.

I have RabbitMQ running locally and all my dev stuff works great, just need/want some tests around it for peace of mind and refactoring process.

lukebyrne avatar Apr 18 '14 11:04 lukebyrne

@lukebyrne I pushed some stuff to master that makes it possible to run Hutch using arbitrary args:

require "hutch/cli"

cli = Hutch::CLI.new
cli.run(command-line-args)

Give this a try and let us know what else may be missing.

michaelklishin avatar Apr 18 '14 13:04 michaelklishin

Hi Michael,

I was able to use that command to good effect. You can see how I did it here in this gist. What are your thoughts? Reasonable approach? Bad? https://gist.github.com/lukebyrne/3a068fb04e744c623a15

I will be deploying my app to Heroku, on the consumers side I am able to connect to the 3rd party service using the .yml configs.

Was wondering how would I also set the producer to send messages to this 3rd party service??

Can I pass in vars to Hutch.connect?

Maybe like so

Hutch.connect("--config", "#{File.expand_path "../../../config/hutch.yml", __FILE__}")

Any help appreciated, really enjoying this library. Thank you.

lukebyrne avatar May 06 '14 01:05 lukebyrne

It's an OK approach, one little suggestion: I'd use Thread#kill instead of Thread.kill (the class method).

michaelklishin avatar May 09 '14 22:05 michaelklishin

Cool thanks for the feedback.

I am picking through the Gem code to try and suss out how I would connect to 3rd party RabbitMQ Cloud provied when I want to publish my messages. What should the Hucth.connect method look like, I know if it can take options and config, I am just unsure about how.

Hutch.connect <<< connect to a remote such as http://www.cloudamqp.com/
Hutch.publish('survey.created.success', screening_id: self.screening_id.to_s)

This is how you do it when you spin up a consumer
consumer: bundle exec hutch --config config/hutch.yml --require users/hutch_consumers.rb

Any directions and suggestions would be much appreciated, will still continue to pick through the code, and docs, trial and error for now.

Cheers,

Luke

lukebyrne avatar May 10 '14 01:05 lukebyrne

Hi Michael, I have sussed it out.

options = YAML.load(File.read(File.expand_path '../config/hutch.yml', __FILE__)).symbolize_keys

require 'hutch'
Hutch.connect({}, options)

lukebyrne avatar May 10 '14 03:05 lukebyrne