Skip to content

Fix flaky pipeline data spec

Allison Browne requested to merge fix-flaky-pipeline-data into master

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

Availability and Testing

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

Merge request reports

Loading