Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration specs #5

Open
hmarr opened this issue Jan 23, 2013 · 8 comments
Open

Integration specs #5

hmarr opened this issue Jan 23, 2013 · 8 comments

Comments

@hmarr
Copy link
Contributor

hmarr commented Jan 23, 2013

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

@lukebyrne
Copy link

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

@michaelklishin
Copy link
Member

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

@lukebyrne
Copy link

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

@michaelklishin
Copy link
Member

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

@lukebyrne
Copy link

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.

@michaelklishin
Copy link
Member

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

@lukebyrne
Copy link

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
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants