1

I am thinking about migrating from a custom Jenkins to Travis for my Ruby on Rails application.

My application runs a Solr server with Sunspot, and queries are tested with rspec on a real Solr instance. I'm using sunspot_solr gem witch has a pre-packaged Solr distribution, and also the sunspot-rails-tester gem to launch Sunspot only when needed.

It works well on our local machines, and on our Jenkins server.

But I'm having trouble with Travis right now...

According to the logs I see on Travis, Sunspot seems to launch:

Sunspot server is starting...
Sunspot server is starting...
Sunspot server is starting...
Sunspot server took 4.10 seconds to start

But when the rspec test try to make a query, I get a 404 error from Solr:

 RSolr::Error::Http:
   RSolr::Error::Http - 404 Not Found
   Error:     Not Found

   Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>*:*</query></delete>"

I have a standard config/sunspot.yml configuration:

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO
    path: /solr/development

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING
    path: /solr/test

Here is my .travis.yml configuration:

language: ruby
rvm:
  - "2.1.3"
cache: bundler
env:
  - DB=postgresql
script:
  - RAILS_ENV=test bundle exec rake db:migrate --trace
  - bundle exec rake db:test:prepare
  - bundle exec rake
before_script:
  - "psql -c 'create database test;' -U postgres"
  - cp config/database.travis.yml config/database.yml
  - cp config/sunspot.travis.yml config/sunspot.yml

EDIT

I found a workaroud here: Rails app: Solr throwing RSolr::Error::Http - 404 Not Found when executing search

My sunspot.yml is now:

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO
    path: /solr/development

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING
    path: /solr/test
    solr_home: solr

I don't know exactly what's wrong here, and why I have to do that only for Travis...

However, when I set "solr_home: solr", solr is installed here :

/home/travis/build/myapp/web/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.1.1/solr/solr

So I have to copy my solr/conf/schema.xml in this folder, which is very unlikely, and I end up with this travis.yml

language: ruby
rvm:
  - "2.1.3"
cache: bundler
env:
  - DB=postgresql
script:
  - RAILS_ENV=test bundle exec rake db:migrate --trace
  - bundle exec rake db:test:prepare
  - bundle exec rake
before_script:
  - "psql -c 'create database \"elcurator-test\";' -U postgres"
  - cp config/database.travis.yml config/database.yml
  - cp config/sunspot.travis.yml config/sunspot.yml
  - mkdir -p /home/travis/build/myapp/web/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.1.1/solr/solr/conf
  - cp solr/conf/schema.xml /home/travis/build/myapp/web/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.1.1/solr/solr/conf

So the main problem remains, why do I get 404 errors when I use the default solr_home (which is "#{Rails.root}/solr" ?

Community
  • 1
  • 1
jvenezia
  • 890
  • 7
  • 10

2 Answers2

0

Another post on SO implies that the port you specified in the sunspot.yml might not be the port used in the end.

Try using port 8983, or whatever is specified as default in: /solr/conf/scripts.conf

ref : Connection refused using Sunspot and Solr in Rails

Community
  • 1
  • 1
Keysharpener
  • 486
  • 3
  • 14
  • Thanks @Keysharpener, I tried to use port 8983, but same problem... Actually the sunspot gem should use sunspot.yml to choose witch port tu use. – jvenezia Jan 09 '15 at 13:06
  • Something seems strange to me here. Aren't you overwriting sunspot.yml when running `cp config/sunspot.travis.yml config/sunspot.yml` in the before_script task? What's the port in `sunspot.travis.yml `? – Keysharpener Jan 09 '15 at 13:30
  • Check my EDIT in the question. Solr now works well, but now my solr conf is ignored. I have no idea what the solr_home option does. – jvenezia Jan 09 '15 at 13:57
0

Check if you correctly versioned the folder /solr/test

it should have the file solr/test/core.properties and a folder solr/test/data

Sunspot 404 missing is usually theses files missing.

This is true for test environment but also for others environments.

Samuel-Zacharie Faure
  • 1,047
  • 11
  • 26