Fix flaky pipeline data spec
What does this MR do?
Fix for a flaky spec #337279 (closed)
Makes it so that each example only contains one build in data[:builds]
From: /Users/allisonbrowne/gitlab/gdk/gitlab/spec/lib/gitlab/data_builder/pipeline_spec.rb:60 :
55: let_it_be(:ci_runner) { create(:ci_runner, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n)}) }
56: let_it_be(:build) { create(:ci_build, pipeline: pipeline, runner: ci_runner) }
57:
58: it 'has runner attributes', :aggregate_failures do
59: binding.pry
=> 60: expect(runner_data[:id]).to eq(ci_runner.id)
61: expect(runner_data[:description]).to eq(ci_runner.description)
62: expect(runner_data[:runner_type]).to eq(ci_runner.runner_type)
63: expect(runner_data[:active]).to eq(ci_runner.active)
64: expect(runner_data[:tags]).to match_array(tag_names)
65: expect(runner_data[:is_shared]).to eq(ci_runner.instance_type?)
[1] pry(#<RSpec::ExampleGroups::GitlabDataBuilderPipeline::Build::BuildWithRunner>)> data[:builds]
=> [{:id=>24,
:stage=>"test",
:name=>"test",
:status=>"pending",
:created_at=>Thu, 05 Aug 2021 08:50:29.000000000 UTC +00:00,
:started_at=>nil,
:finished_at=>nil,
:duration=>nil,
:queued_duration=>44796.1814,
:when=>"on_success",
:manual=>false,
:allow_failure=>false,
:user=>nil,
:runner=>
{:id=>7,
:description=>"My runner1",
:runner_type=>"instance_type",
:active=>true,
:is_shared=>true,
:tags=>["tag-1", "tag-2"]},
:artifacts_file=>{:filename=>nil, :size=>nil},
:environment=>nil}]
versus the prior code:
From: /Users/allisonbrowne/gitlab/gdk/gitlab/spec/lib/gitlab/data_builder/pipeline_spec.rb:60 :
55: let_it_be(:ci_runner) { create(:ci_runner, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n)}) }
56: let_it_be(:build) { create(:ci_build, pipeline: pipeline, runner: ci_runner) }
57:
58: it 'has runner attributes', :aggregate_failures do
59: binding.pry
=> 60: expect(runner_data[:id]).to eq(ci_runner.id)
61: expect(runner_data[:description]).to eq(ci_runner.description)
62: expect(runner_data[:runner_type]).to eq(ci_runner.runner_type)
63: expect(runner_data[:active]).to eq(ci_runner.active)
64: expect(runner_data[:tags]).to match_array(tag_names)
65: expect(runner_data[:is_shared]).to eq(ci_runner.instance_type?)
[1] pry(#<RSpec::ExampleGroups::GitlabDataBuilderPipeline::Build::BuildWithRunner>)> build_data
=> {:id=>20,
:stage=>"test",
:name=>"test",
:status=>"pending",
:created_at=>Thu, 05 Aug 2021 08:50:29.000000000 UTC +00:00,
:started_at=>nil,
:finished_at=>nil,
:duration=>nil,
:queued_duration=>44498.893407,
:when=>"on_success",
:manual=>false,
:allow_failure=>false,
:user=>nil,
:runner=>
{:id=>6,
:description=>"My runner1",
:runner_type=>"instance_type",
:active=>true,
:is_shared=>true,
:tags=>["tag-1", "tag-2"]},
:artifacts_file=>{:filename=>nil, :size=>nil},
:environment=>nil}
[2] pry(#<RSpec::ExampleGroups::GitlabDataBuilderPipeline::Build::BuildWithRunner>)> data[:builds]
=> [{:id=>19,
:stage=>"test",
:name=>"test",
:status=>"pending",
:created_at=>Thu, 05 Aug 2021 08:50:29.000000000 UTC +00:00,
:started_at=>nil,
:finished_at=>nil,
:duration=>nil,
:queued_duration=>44498.890676,
:when=>"on_success",
:manual=>false,
:allow_failure=>false,
:user=>nil,
:runner=>nil,
:artifacts_file=>{:filename=>nil, :size=>nil},
:environment=>nil},
{:id=>20,
:stage=>"test",
:name=>"test",
:status=>"pending",
:created_at=>Thu, 05 Aug 2021 08:50:29.000000000 UTC +00:00,
:started_at=>nil,
:finished_at=>nil,
:duration=>nil,
:queued_duration=>44498.893407,
:when=>"on_success",
:manual=>false,
:allow_failure=>false,
:user=>nil,
:runner=>
{:id=>6,
:description=>"My runner1",
:runner_type=>"instance_type",
:active=>true,
:is_shared=>true,
:tags=>["tag-1", "tag-2"]},
:artifacts_file=>{:filename=>nil, :size=>nil},
:environment=>nil}]
data[:builds]
seems to have a non-deterministic ordering.
That is because the class Gitlab::DataBuilder::Pipeline
uses pipeline.builds.latest
on line 22 which queries for
SELECT "ci_builds".* FROM "ci_builds" WHERE "ci_builds"."type" = 'Ci::Build' AND "ci_builds"."commit_id" = 14 AND ("ci_builds"."retried" = FALSE OR "ci_builds"."retried" IS NULL)
with no order specified which will return a non-deterministic order in postgres.
It might be good to provide an order in a follow up?
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
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 Allison Browne