O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

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

316 visualizações

Publicada em

Case da Resultados Digitais sobre como diminuir o tempo de performance de uma suíte de 12 mil testes automatizados de 25 minutos para 13 minutos.
Apresentação realizada por @jonatasdp e @xptavares no evento TDC (The Developers Conference) edição Florianópolis.

Publicada em: Software
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

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

  1. 1. Optimizing build time Performance running tests Jônatas Paganini @jonatasdp Alexandre Tavares @xptavares
  2. 2. test suite
  3. 3. RSpec
  4. 4. 12K assertions
  5. 5. ~25’ Build time / 3 machines
  6. 6. >100’ in localhost
  7. 7. MONOLITHIC APP
  8. 8. NOW
  9. 9. ~13’ Build time / 4 machines
  10. 10. ?
  11. 11. Little Changes on factories
  12. 12. girl ?factory
  13. 13. Avoid callbacks Callbacks can be lazy and unuseful running all the time
  14. 14. Model#skip_callback To avoid run the the hook each factory
  15. 15. Coverage?
  16. 16. after(:create) To run it in a specific factory
  17. 17. Profiling Associations
  18. 18. Specializing factories
  19. 19. Specialized factories
  20. 20. Associations Results
  21. 21. Use lazy Associations Associations naturally invokes their own factories.
  22. 22. Avoid factory: for associations Associations naturally invokes their own factories.
  23. 23. association &block
  24. 24. association &block
  25. 25. quick wins
  26. 26. +1GEM factory_girl-seeds
  27. 27. How it works ?
  28. 28. Transform factories into seeds
  29. 29. SQL transactions
  30. 30. use seed instead of create
  31. 31. Use build_stubbed Instead of create
  32. 32. hack sign_in Avoid touch database each login
  33. 33. ConfigureRSpec
  34. 34. sign_inbuild_stubbed
  35. 35. Use stub to avoid inflateassociations
  36. 36. build Instead of create
  37. 37. CI Improvements We use CircleCI ● Split specs by context ● Hack postgres.conf ● Postgresql on Memory
  38. 38. Splitspecs by Context
  39. 39. CircleCi divide tests by time NOT context
  40. 40. SplitSpecs by DIRECTORY
  41. 41. postgres.conf
  42. 42. fsync = ’off’
  43. 43. full_page_writes = ’off’
  44. 44. checkpoint_segments = ’100’ checkpoint_timeout = ’45 min’
  45. 45. data_directory = ’/tmp/postgres-on-memory’
  46. 46. dir=/tmp/postgresql-on-memory
  47. 47. dir=/tmp/postgresql-on-memory mkdir $dir
  48. 48. dir=/tmp/postgresql-on-memory mkdir $dir mount -o size=200M,mode=0666 tmpfs $dir
  49. 49. dir=/tmp/postgresql-on-memory mkdir $dir mount -o size=200M,mode=0666 tmpfs $dir chown postgres:postgres $dir
  50. 50. 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
  51. 51. NEXT LEVEL <what> run <when>
  52. 52. hardcore scenarios Split Specs
  53. 53. Nightly Build
  54. 54. if [ -n "${RUN_NIGHTLY_BUILD}" ]; rspec spec/features --tag "~smoke"
  55. 55. if [ -n "${RUN_NIGHTLY_BUILD}" ]; rspec spec/features --tag "~smoke" if [ -z "${RUN_NIGHTLY_BUILD}" ]; rspec spec/features --tag "smoke"
  56. 56. http://shipit.resultadosdigitais.com.br/blog ● /ruby-e-rspec-melhorando-a-legibilidade-de-seus-testes/ ● /rspec-performance-tips/ ● /otimizando-testes-factory-girl-e-rspec/
  57. 57. 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
  58. 58. Thanks! Github: xptavares Twitter: xptavares E-mail: xptavares@gmail.com Github: jonatas Twitter: jonatasdp E-mail: jonatasdp@gmail.com shipit.resultadosdigitais.com.br/trabalhe-conosco/
  59. 59. +10 cents
  60. 60. False positive Fail sometimes :(
  61. 61. Problem
  62. 62. Use contexts Avoid nested expectations
  63. 63. describe your code instead of just write assertions
  64. 64. Thanks! Github: xptavares Twitter: xptavares E-mail: xptavares@gmail.com Github: jonatas Twitter: jonatasdp E-mail: jonatasdp@gmail.com shipit.resultadosdigitais.com.br/trabalhe-conosco/

×