Create the draft merge requests once in the on-finish settings worker spec

What does this MR do and why?

ee/spec/workers/ai/flow_triggers/apply_on_finish_settings_worker_spec.rb created its draft merge requests with let! and a .tap that also created the session link, so every example in the chain-walk and ready_merge_requests_on_finish groups paid for one to four merge request creations (repository, diff, branch). The merge requests now come from let_it_be_with_reload once per group; the links to the per-example session stay per example (let! / before), and the auto-merge context keeps its own per-example merge request. No example or assertion changed.

Measured on this machine, whole file, same seed, nothing else running (EVENT_PROF=sql.active_record FPROF=1):

before after
wall clock 1 min 16 s 56 s
SQL statements (sql.active_record events) 10,256 8,575
time in factories 38.1 s (568 factory calls) 18.9 s (517 factory calls)
examples 92 / 0 failures 92 / 0 failures

On the Test File Runtime Overview dashboard the file is the fourth slowest in the dap_events group (42.1 s over 30 days, 8% of the group).

How to reproduce (on master)

EVENT_PROF=sql.active_record FPROF=1 bin/rspec ee/spec/workers/ai/flow_triggers/apply_on_finish_settings_worker_spec.rb --seed 1234
# 1 min 16 s, Total events: 10,256, Time spent in factories: 38.1 s (568 factory calls)

How to verify (on this branch)

EVENT_PROF=sql.active_record FPROF=1 bin/rspec ee/spec/workers/ai/flow_triggers/apply_on_finish_settings_worker_spec.rb --seed 1234
# 56 s, Total events: 8,575, Time spent in factories: 18.9 s (517 factory calls), 92 examples, 0 failures

bundle exec rubocop ee/spec/workers/ai/flow_triggers/apply_on_finish_settings_worker_spec.rb
# no offenses detected

References

Related to #630519 Related to &23524

Merge request reports

Loading
Loading