Date post: | 14-Apr-2017 |
Category: |
Technology |
Upload: | jonatas-paganini |
View: | 344 times |
Download: | 0 times |
Optimizing build timePerformance running tests
Jônatas Paganini @jonatasdp
test suite
RSpec
12K
assertions
~25’
Build time / 3 machines
>100’
in localhost
MONOLITHIC APP
NOW
~13’
Build time / 4 machines
?
Little Changes on
factories
girl ?factory
Avoid callbacksCallbacks can be lazy and
unuseful running all the time
Model#skip_callback
To avoid run the the hook each factory
Coverage ?
after(:create)
To run it in a specific factory
Profiling Associations
Specializing
factories
Specialized factories
Associations Results
Use lazy AssociationsAssociations naturally invokes their own factories.
Avoid factory: for associationsAssociations naturally invokes their own factories.
association &block
association &block
quick wins
Use build_stubbedInstead of create
hack sign_inAvoid touch database each login
Configure RSpec
sign_in build_stubbed
Use stub to avoid
inflate associations
build Instead of create
CI ImprovementsWe use CircleCI
● Split specs by context● Hack postgres.conf● Postgresql on Memory
Split specs by
Context
CircleCi divide tests by time NOT
context
Split Specs by
DIRECTORY
postgres.conf
fsync = ’off’
full_page_writes = ’off’
checkpoint_segments = ’100’checkpoint_timeout = ’45 min’
data_directory = ’/tmp/postgres-on-memory’
dir=/tmp/postgresql-on-memory
dir=/tmp/postgresql-on-memory
mkdir $dir
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
chown postgres:postgres $dir
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
chown postgres:postgres $dir
sudo su - postgres -c \
'/usr/lib/postgresql/9.4/bin/initdb \
--encoding=UTF8 --pgdata=$dir
NEXT LEVEL<what> run <when>
hardcore scenarios
Split Specs
Nightly Build
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
if [ -z "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "smoke"
http://shipit.resultadosdigitais.com.br/blog
● /ruby-e-rspec-melhorando-a-legibilidade-de-seus-testes/● /rspec-performance-tips/● /otimizando-testes-factory-girl-e-rspec/
Conclusion
● Avoid touch database● Avoid callbacks no sense● Avoid things you don’t need● Write specialized factories● Rate (classify) your test● Benchmark all isolated steps
It’s all about responsibilities
Thanks!@jonatasdp
http://ideia.me
http://shipit.resultadosdigitais.com.br