Question

Just to start out, I am extremely new to testing my cookbooks. I've been working in cookbooks for a couple of months now and understand things fairly well, but our project has been very lax in adding testing. I'm attempting to drag us into testing these as well.

My test, as it stands now, checks that a service has started. My problem is, to call the test a success, I'd really like to check, through the upstart log file, that the software made it through its startup steps. One of these steps is to contact a RabbitMQ server and register to listen on four separate exchanges. This takes some time.

I was looking to use the following:

describe_recipe 'my_cookbook::test' do

  it " testing that the service is running" do
    service('foo').must_be_running
  end

  it " testing that the log file contains We're Up!" do
    file('/var/log/upstart/foo').must_include 'We're Up!'
  end

end

... but I get a failure because it attempts to check the upstart log before it has even been created by the service. Even if I could get it to wait until the file has been created, I really need to create a, say, 5 second delay, during which the RabbitMQ connections would be established.

Does anyone know how to deal with this timing issue?

Was it helpful?

Solution

Although I would also suggest, as sethvargo did for me, investigating Test Kitchen, just in case someone else needs the ability to add sleeps to their minitests, it can be done this way:

it "sleeping" do; puts "need to say something here or the sleep will not happen at the right time"; sleep 5; end

A bit hackish and timing issues should never be solved by sleeps, but I won't presume to know what you might need it for ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top