![Page 1: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/1.jpg)
Optimizing build timePerformance running tests
Jônatas Paganini @jonatasdp
![Page 2: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/2.jpg)
test suite
![Page 3: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/3.jpg)
RSpec
![Page 4: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/4.jpg)
12K
assertions
![Page 5: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/5.jpg)
~25’
Build time / 3 machines
![Page 6: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/6.jpg)
>100’
in localhost
![Page 7: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/7.jpg)
MONOLITHIC APP
![Page 8: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/8.jpg)
NOW
![Page 9: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/9.jpg)
~13’
Build time / 4 machines
![Page 10: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/10.jpg)
?
![Page 11: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/11.jpg)
Little Changes on
factories
![Page 12: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/12.jpg)
girl ?factory
![Page 13: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/13.jpg)
Avoid callbacksCallbacks can be lazy and
unuseful running all the time
![Page 14: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/14.jpg)
Model#skip_callback
To avoid run the the hook each factory
![Page 15: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/15.jpg)
Coverage ?
![Page 16: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/16.jpg)
after(:create)
To run it in a specific factory
![Page 17: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/17.jpg)
Profiling Associations
![Page 18: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/18.jpg)
Specializing
factories
![Page 19: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/19.jpg)
Specialized factories
![Page 20: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/20.jpg)
Associations Results
![Page 21: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/21.jpg)
Use lazy AssociationsAssociations naturally invokes their own factories.
![Page 22: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/22.jpg)
Avoid factory: for associationsAssociations naturally invokes their own factories.
![Page 23: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/23.jpg)
association &block
![Page 24: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/24.jpg)
association &block
![Page 25: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/25.jpg)
quick wins
![Page 26: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/26.jpg)
Use build_stubbedInstead of create
![Page 27: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/27.jpg)
hack sign_inAvoid touch database each login
![Page 28: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/28.jpg)
Configure RSpec
![Page 29: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/29.jpg)
sign_in build_stubbed
![Page 30: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/30.jpg)
Use stub to avoid
inflate associations
![Page 31: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/31.jpg)
![Page 32: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/32.jpg)
![Page 33: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/33.jpg)
build Instead of create
![Page 34: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/34.jpg)
![Page 35: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/35.jpg)
![Page 36: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/36.jpg)
![Page 37: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/37.jpg)
CI ImprovementsWe use CircleCI
● Split specs by context● Hack postgres.conf● Postgresql on Memory
![Page 38: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/38.jpg)
Split specs by
Context
![Page 39: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/39.jpg)
CircleCi divide tests by time NOT
context
![Page 40: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/40.jpg)
Split Specs by
DIRECTORY
![Page 41: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/41.jpg)
postgres.conf
![Page 42: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/42.jpg)
fsync = ’off’
![Page 43: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/43.jpg)
full_page_writes = ’off’
![Page 44: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/44.jpg)
checkpoint_segments = ’100’checkpoint_timeout = ’45 min’
![Page 45: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/45.jpg)
data_directory = ’/tmp/postgres-on-memory’
![Page 46: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/46.jpg)
dir=/tmp/postgresql-on-memory
![Page 47: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/47.jpg)
dir=/tmp/postgresql-on-memory
mkdir $dir
![Page 48: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/48.jpg)
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
![Page 49: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/49.jpg)
dir=/tmp/postgresql-on-memory
mkdir $dir
mount -o size=200M,mode=0666 tmpfs $dir
chown postgres:postgres $dir
![Page 50: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/50.jpg)
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 51: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/51.jpg)
NEXT LEVEL<what> run <when>
![Page 52: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/52.jpg)
hardcore scenarios
Split Specs
![Page 53: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/53.jpg)
Nightly Build
![Page 54: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/54.jpg)
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
![Page 55: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/55.jpg)
if [ -n "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "~smoke"
if [ -z "${RUN_NIGHTLY_BUILD}" ];
rspec spec/features --tag "smoke"
![Page 56: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/56.jpg)
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 57: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/57.jpg)
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 58: Otimizando tempo de build: performance da suíte de testes](https://reader033.vdocument.in/reader033/viewer/2022051708/5889611e1a28abef658b6803/html5/thumbnails/58.jpg)
Thanks!@jonatasdp
http://ideia.me
http://shipit.resultadosdigitais.com.br