One spec parallel run via ENV vars

envars
rspec
paralellism
2.0

#1

We have one rspec test which we run via a rake task and we pass in multiple countries via the Build settings > Environment variables.

We could create one rspec test for each country to get parallel runs.

Is it possible to use the ENV vars to run one spec in parallel?

Thanks!


#2

With 2.0 you have full control over your config so just pass that env var to rake.


#3

Thanks for the reply! Here’s a little more information.

So I currently have…

Rspec test file:
single_spec.rb

Environment args:
COUNTRY=au,us,it

config.yml:

  • run:
    name: Rake worldwide
    command: |
    bundle exec rake worldwide

Looking through https://circleci.com/docs/2.0/parallelism-faster-jobs/ I can only see the option to run individual files in parallel, which would mean duplicating the spec to ‘au_single_spec.rb’, ‘us_single_spec.rb’, ‘it_single_spec.rb’ and running something like ‘circleci tests glob ./spec/*_spec.rb’


#4

Something like this

root@0b86d893c3b2:/$ export CIRCLE_NODE_INDEX=0
root@0b86d893c3b2:/$ echo "au,us,it" | awk -F',' -v x=$CIRCLE_NODE_INDEX '{++x; print $x}'
au
root@0b86d893c3b2:/$ export CIRCLE_NODE_INDEX=1
root@0b86d893c3b2:/$ echo "au,us,it" | awk -F',' -v x=$CIRCLE_NODE_INDEX '{++x; print $x}'
us
root@0b86d893c3b2:/$ export CIRCLE_NODE_INDEX=2
root@0b86d893c3b2:/$ echo "au,us,it" | awk -F',' -v x=$CIRCLE_NODE_INDEX '{++x; print $x}'
it

#5

Ah… dug through the v1 docs for CIRCLE_NODE_INDEX and it all makes sense now.

Thanks for your help!


#6