Created
September 5, 2013 11:26
-
-
Save blimey74/6448929 to your computer and use it in GitHub Desktop.
A gist for adding a CI rake task for project hydra applications so that Jetty gets started and stopped between test runs, this code should guarantee that Solr is up before starting your rspec or cucumber tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jettywrapper' | |
require 'rsolr' | |
desc 'Start up jetty and run rspec and cucumber tests' | |
task :ci => ['jetty:unzip', 'jetty:config'] do | |
puts 'running continuous integration' | |
jetty_params = Jettywrapper.load_config | |
error = Jettywrapper.wrap(jetty_params) do | |
ping_solr #check solr is up before starting the tests | |
Rake::Task['spec'].invoke | |
Rake::Task['cucumber'].invoke | |
end | |
raise "test failures: #{error}" if error | |
end | |
#Because Jetty takes a long time to start Solr and Fedora we need to wait for it before starting the tests | |
#Following code attempts to connect to Solr and run a simple query, if the connection refused it catches | |
#this error and sleeps for 5 seconds before trying again until successful | |
def ping_solr | |
begin | |
solr = RSolr.connect :url => 'http://localhost:8983/solr' | |
response = solr.get 'select', :params => {:q => '*:*'} | |
puts 'Solr is up!' | |
return | |
rescue Errno::ECONNREFUSED | |
puts 'Solr not up yet, sleeping for 10 seconds... zzz' | |
sleep 10 | |
ping_solr | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment