Skip to content

Use factory prof to find un-needed db access in tests

Allison Browne requested to merge ab-use-factory-prof into master

What does this MR do?

As part of the performance training we watched a video on Factory doctor.

I tried it out and made a few small perf gains.

In total takes about 11 seconds off the test suite:

FDOC=1 rspec spec/models/error_tracking/project_error_tracking_setting_spec.rb

Total (potentially) bad examples: 39
Total wasted time: 00:00.908 => 00:00(after)

FDOC=1 bundle exec rspec spec/models/analytics/cycle_analytics/project_stage_spec.rb
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)

Total (potentially) bad examples: 10
Total wasted time: 00:02.045 => 00:00(after)


FDOC=1 bundle exec rspec spec/models/clusters/cluster_spec.rb

Total wasted time: 00:10.247(before) => 00:07.399(after)


FDOC=1 bundle exec rspec spec/models/merge_request_spec.rb:278
Total wasted time: 00:06.004(before) => 00:01.778(after)

I stopped here but I think it wouldn't hurt do document that devs should run this prior to opening a new MR.

I found that the tool says the project and merge_request specs have around a minute of wasted time due to un-needed factories but just wanted to make a small iterative change.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports