Page 1
Optimizing build timePerformance running tests
Jônatas Paganini @jonatasdp Alexandre Tavares @xptavares
Page 5
~25’
Build time / 3 machines
Page 6
>100’
in localhost
Page 9
~13’
Build time / 4 machines
Page 11
Little Changes on
factories
Page 13
Avoid callbacksCallbacks can be lazy and
unuseful running all the time
Page 14
Model#skip_callback
To avoid run the the hook each factory
Page 16
after(:create)
To run it in a specific factory
Page 17
Profiling Associations
Page 18
Specializing
factories
Page 19
Specialized factories
Page 20
Associations Results
Page 21
Use lazy AssociationsAssociations naturally invokes their own factories.
Page 22
Avoid factory: for associationsAssociations naturally invokes their own factories.
Page 23
association &block
Page 24
association &block
Page 26
+1 GEMfactory_girl-seeds
Page 28
Transform factories into
seeds
Page 30
use seed instead of create
Page 31
Use build_stubbedInstead of create
Page 32
hack sign_inAvoid touch database each login
Page 34
sign_in build_stubbed
Page 35
Use stub to avoid
inflate associations
Page 38
build Instead of create
Page 42
CI ImprovementsWe use CircleCI
● Split specs by context● Hack postgres.conf● Postgresql on Memory
Page 43
Split specs by
Context
Page 44
CircleCi divide tests by time NOT
context
Page 45
Split Specs by
DIRECTORY
Page 48
full_page_writes = ’off’
Page 49
checkpoint_segments = ’100’checkpoint_timeout = ’45 min’
Page 50
data_directory = ’/tmp/postgres-on-memory’
Page 51
dir=/tmp/postgresql-on-memory
Page 52
dir=/tmp/postgresql-on-memory
mkdir $dir
Page 53
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
Page 54
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
chown postgres:postgres $dir
Page 55
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
Page 56
NEXT LEVEL<what> run <when>
Page 57
hardcore scenarios
Split Specs
Page 59
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
Page 60
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
if [ -z "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "smoke"
Page 61
http://shipit.resultadosdigitais.com.br/blog
● /ruby-e-rspec-melhorando-a-legibilidade-de-seus-testes/● /rspec-performance-tips/● /otimizando-testes-factory-girl-e-rspec/
Page 62
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
Page 63
Thanks!Github: xptavares
Twitter: xptavares
E-mail: [email protected]
Github: jonatas
Twitter: jonatasdp
E-mail: [email protected]
shipit.resultadosdigitais.com.br/trabalhe-conosco/
Page 65
False positiveFail sometimes :(
Page 67
Use contextsAvoid nested expectations
Page 69
describe your code instead of just write assertions
Page 70
Thanks!Github: xptavares
Twitter: xptavares
E-mail: [email protected]
Github: jonatas
Twitter: jonatasdp
E-mail: [email protected]
shipit.resultadosdigitais.com.br/trabalhe-conosco/