Configuring travis with parallel test - ruby-on-rails

I've been struggling for most of the day to set up travis with parallel_tests, and am unable to understand why it isn't working.
# .travis.yml
language: ruby
rvm:
- 2.2.2
env:
- DB=postgresql
cache: bundler
addons:
postgresql: "9.4"
services:
- postgresql
- redis
script:
- RAILS_ENV=test bundle exec rake teaspoon
- RAILS_ENV=test xvfb-run -a bundle exec rake parallel:spec
before_script:
- "sh -e /etc/init.d/xvfb start"
- cp config/database.travis.yml config/database.yml
- export PARALLEL_TEST_PROCESSORS=4
- RAILS_ENV=development bundle exec rake db:drop
- RAILS_ENV=development bundle exec rake db:create
- RAILS_ENV=development bundle exec rake db:migrate
- bundle exec rake parallel:create
- bundle exec rake parallel:prepare
My database.travis.yml
development:
adapter: postgresql
encoding: utf8
host: localhost
database: adiq_dev
pool: 25
username: postgres
password:
test:
adapter: postgresql
encoding: utf8
host: localhost
database: adiq_test<%= ENV['TEST_ENV_NUMBER'] %>
pool: 25
username: postgres
password:
On parallel prepare, I keep getting this
You have 174 pending migrations:
...
...
Run rake db:migrate to update your database then try again.
The command "bundle exec rake parallel:prepare" failed and exited with 1 during .
The exact chain of commands seems to work fine on my local
I don't get it, where am I going wrong?
Any suggestions will be invaluable....I have spent a lot of hours trying to make this work.

The parallel:load_schema was the trick. Updated file...
# .travis.yml
language: ruby
rvm:
- 2.2.2
env:
- DB=postgresql
cache: bundler
addons:
postgresql: "9.4"
services:
- postgresql
- mongodb
- redis
script:
- RAILS_ENV=test bundle exec rake teaspoon
- RAILS_ENV=test xvfb-run -a bundle exec rake parallel:spec
before_script:
- "sh -e /etc/init.d/xvfb start"
- cp config/database.travis.yml config/database.yml
- cp config/mongoid.travis.yml config/mongoid.yml
- export PARALLEL_TEST_PROCESSORS=4
- RAILS_ENV=development bundle exec rake db:create db:migrate
- bundle exec rake parallel:create parallel:load_schema parallel:prepare

Related

Circle CI fails to execute psql command when running rake db:structure:load

So this is my config.yml
version: 2.1
orbs:
queue: eddiewebb/queue#1.5.0
executors:
node_postgres_redis:
docker:
- image: circleci/ruby:2.4.10-node-browsers
environment:
CC_TEST_REPORTER_ID: 7ceff1524bdc09dsd3e232321cf9daa531154170d590823232eddqw2330f3570
PGHOST: 127.0.0.1
RAILS_ENV: test
TEST_REPORT_PATH: "test/reports"
- image: circleci/postgres:9.6.2-alpine
environment:
POSTGRES_USER: circleci
POSTGRES_DB: circleci-jet-test
POSTGRES_PASSWORD: ""
- image: circleci/redis:3.2
ubuntu:
machine:
image: ubuntu-1604:202004-01
commands:
setup_and_run_test:
steps:
- checkout
# Restore bundle cache
- restore_cache:
key: jet-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
# imagemagic
- run:
name: Setup Image Magick
command: |
sudo apt-get install libmagickwand-dev imagemagick imagemagick-6.q16 libmagickcore-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7/bin-q16/Magick-config /usr/bin/Magick-config
- run:
name: Install Bundler
command: |
gem install bundler -v 1.17.3
# Install gem dependencies
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
# Store bundle cache
- save_cache:
key: jet-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Database setup
- run:
name: Database Setup
command: |
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:structure:load
Everythings runs properly until it tries to execute
bundle exec rake db:structure:load
Then it throws this error which is a bit weird
failed to execute:
psql -q -f /home/circleci/circleci-jet/db/structure.sql *****_test
Please check the output above for any errors and make sure that psql is installed in your PATH and has proper permissions.
I cannot understand this error and what needs to be done on my side.
Anyone with examples, please can show me direction.
Thanks

What is the required setup of Travis when using webpacker on Rails 5?

I am using travis for the first time and I don't know how to correctly add webpacker on it?
Here is what I have for now in .travis.yml
language: ruby
rvm:
- 2.4.4
addons:
postgresql: "9.4"
before_install:
- "echo 'gem: --no-document' > ~/.gemrc"
- "echo '--colour' > ~/.rspec"
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
before_script:
- bundle exec rake db:create db:migrate RAILS_ENV=test
- bundle exec rails webpacker:compile
Here is the build error
$ bundle exec rails webpacker:compile
Webpacker is installed 🎉 🍰
Using /home/travis/build/bill/ivan/config/webpacker.yml file for setting up webpack paths
Compiling…
Compilation failed:
/home/travis/build/bill/ivan/vendor/bundle/ruby/2.4.0/gems/webpacker-3.5.5/lib/webpacker/webpack_runner.rb:11:in `exec': No such file or directory - /home/travis/build/bill/ivan/node_modules/.bin/webpack (Errno::ENOENT)
from /home/travis/build/bill/ivan/vendor/bundle/ruby/2.4.0/gems/webpacker-3.5.5/lib/webpacker/webpack_runner.rb:11:in `block in run'
from /home/travis/build/bill/ivan/vendor/bundle/ruby/2.4.0/gems/webpacker-3.5.5/lib/webpacker/webpack_runner.rb:10:in `chdir'
from /home/travis/build/bill/ivan/vendor/bundle/ruby/2.4.0/gems/webpacker-3.5.5/lib/webpacker/webpack_runner.rb:10:in `run'
from /home/travis/build/bill/ivan/vendor/bundle/ruby/2.4.0/gems/webpacker-3.5.5/lib/webpacker/runner.rb:6:in `run'
from ./bin/webpack:15:in `<main>'
The command "bundle exec rails webpacker:compile" failed and exited with 1 during .
Your build has been stopped.
No such file or directory - /home/travis/build/bill/ivan/node_modules/.bin/webpack (Errno::ENOENT)
it's in my rails app tought
well maybe it could help someone else: so here the setup that is finally working
language: ruby
rvm:
- 2.4.4
addons:
postgresql: "9.4"
before_install:
- "echo 'gem: --no-document' > ~/.gemrc"
- "echo '--colour' > ~/.rspec"
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
before_script:
- bundle exec rake db:create db:migrate RAILS_ENV=test
cache:
bundler: true
directories:
- node_modules
yarn: true
install:
- bundle install
- nvm install node
- node -v
- npm i -g yarn
- yarn
script:
- bundle exec rails webpacker:compile
- bundle exec rails spec

Circle Ci- Run rspec tests parallely

I added an additional container in circle ci and tried to run tests parallaly.
This is my circle.yml file.
machine:
ruby:
version: 2.3.0
database:
post:
- cp config/sunspot.ci.yml config/sunspot.yml
- bundle exec sunspot-solr start -p 8981
dependencies:
pre:
- sudo apt-get update; sudo apt-get -y install solr-tomcat
test:
override:
- rvm use 2.3.0 && bundle exec rspec --color --format progress:
environment:
RAILS_ENV: test
parallel: true
files:
- "spec/**/*_spec.rb"
but tests don't seem to be running in parallel.
What am I missing? Thanks in advance
For some reason removing rvm use 2.3.0 from test section fixed my problem.
machine:
ruby:
version: 2.3.0
database:
# After default database task finished
post:
# Circle CI already replace our original sunspot.yml, replace it with backup copy `config/sunspot.yml.ci`
- cp config/sunspot.ci.yml config/sunspot.yml
- bundle exec sunspot-solr start -p 8981
dependencies:
pre:
- sudo apt-get update; sudo apt-get -y install solr-tomcat
test:
override:
- bundle exec rspec --tag ~#flaky --color --profile 20 --format progress:
timeout: 240
environment:
RAILS_ENV: test
parallel: true
files:
- my files here

Rails app not restarting following deletion of solr folder

OS: Ubuntu 14.04
RAILS 3.2
In my gemfile, I have:
gem 'sunspot_rails'
gem 'sunspot_solr'
The application was running fine, until I cleaned it up, and part of the process included deleting the app/solr directory.
In my config/sunspot.yml file, I have:
staging:
solr:
hostname: localhost
port: 8983
log_level: INFO
path: /solr/staging
I ran:
RAILS_ENV=staging RAILS_GROUPS=assets bundle exec rake assets:precompile
then:
rm -Rf /home/app/solr
mkdir /home/app/solr
mkdir /home/app/solr/staging
rake sunspot:solr:stop
RAILS_ENV=staging bundle exec rake sunspot:solr:start
screen -d -m sh -c 'RAILS_ENV=staging bundle exec rakesunspot:solr:reindex[500] > /home/installio/app/solr/indexing_out.txt'
The app/solr directory has in it the following structuere
pids/staging/sunspot-solr-staging.pid
data (empty directory)
staging (empty directory)
And I am getting the "something went wrong message).
From the sunspot-solr-staging.log:
SEVERE: Unable to create core: collection1
org.apache.solr.common.SolrException: Could not load config for solrconfig.xml
Any ideas?

Rails Whenever gem cron fe_sendauth: no password supplied

I am running a Rails server that periodically runs a rake task using whenever gem and cron.
I can run the rake task using these successfully. On my remote server, I am running that as the root. This second attempt also works.
RAILS_ENV=production rake fetch_myitems
// attempt 1
//attempt 2
/bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'
After debugging, this is what I ended up with as the source of error. I understand that this is related to database.yml. However I can deploy to my live production server successfully and calling RAILS_ENV=production rake fetch_myitems does not trigger this error so I am confused as to what to do.
PG::ConnectionBad: fe_sendauth: no password supplied
Crontab -l
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'
For some reason in /etc/default/unicorn file the APP_DATABASE_PASSWORD does not get updated even if I reload nginx along with unicorn.
My fix was to manually override the password in database.yml.
My guess is that your database.yml file looks something like:
production:
adapter: postgresql
encoding: unicode
database: test-postgres_production
pool: 5
username: rails
password: <%= ENV['PGPASS'] %>
Meaning that the password is obtained from an environment variable. Your cronjob should look something like:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production PGPASS=your_database_password_here bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'
Hope that sorts you.

Resources