Otimizando tempo de build: performance da suíte de testes

70
Optimizing build time Performance running tests Jônatas Paganini @jonatasdp Alexandre Tavares @xptavares

Transcript of Otimizando tempo de build: performance da suíte de testes

Optimizing build timePerformance running tests

Jônatas Paganini @jonatasdp Alexandre Tavares @xptavares

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

+1 GEMfactory_girl-seeds

How it works ?

Transform factories into

seeds

SQL transactions

use seed instead of create

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"

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!Github: xptavares

Twitter: xptavares

E-mail: [email protected]

Github: jonatas

Twitter: jonatasdp

E-mail: [email protected]

shipit.resultadosdigitais.com.br/trabalhe-conosco/

+ 10 cents

False positiveFail sometimes :(

Problem

Use contextsAvoid nested expectations

describe your code instead of just write assertions

Thanks!Github: xptavares

Twitter: xptavares

E-mail: [email protected]

Github: jonatas

Twitter: jonatasdp

E-mail: [email protected]

shipit.resultadosdigitais.com.br/trabalhe-conosco/