summaryrefslogtreecommitdiff
path: root/qa/spec/specs/parallel_runner_spec.rb
blob: 67d94a1f64809324020b2107c9751cde38d94365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

describe QA::Specs::ParallelRunner do
  include Helpers::StubENV

  before do
    allow(QA::Runtime::Scenario).to receive(:attributes).and_return(parallel: true)
    stub_env('GITLAB_QA_ACCESS_TOKEN', 'skip_token_creation')
  end

  it 'passes args to parallel_tests' do
    expect_cli_arguments(['--tag', '~orchestrated', *QA::Specs::Runner::DEFAULT_TEST_PATH_ARGS])

    subject.run(['--tag', '~orchestrated', *QA::Specs::Runner::DEFAULT_TEST_PATH_ARGS])
  end

  it 'passes a given test path to parallel_tests and adds a separator' do
    expect_cli_arguments(%w[-- qa/specs/features/foo])

    subject.run(%w[qa/specs/features/foo])
  end

  it 'passes tags and test paths to parallel_tests and adds a separator' do
    expect_cli_arguments(%w[--tag smoke -- qa/specs/features/foo qa/specs/features/bar])

    subject.run(%w[--tag smoke qa/specs/features/foo qa/specs/features/bar])
  end

  it 'passes tags and test paths with separators to parallel_tests' do
    expect_cli_arguments(%w[-- --tag smoke -- qa/specs/features/foo qa/specs/features/bar])

    subject.run(%w[-- --tag smoke -- qa/specs/features/foo qa/specs/features/bar])
  end

  it 'passes supported environment variables' do
    # Test only env vars starting with GITLAB because some of the others
    # affect how the runner behaves, and we're not concerned with those
    # behaviors in this test
    gitlab_env_vars = QA::Runtime::Env::ENV_VARIABLES.reject { |v| !v.start_with?('GITLAB') }

    gitlab_env_vars.each do |k, v|
      stub_env(k, v)
    end

    gitlab_env_vars['QA_RUNTIME_SCENARIO_ATTRIBUTES'] = '{"parallel":true}'

    expect_cli_arguments([], gitlab_env_vars)

    subject.run([])
  end

  def expect_cli_arguments(arguments, env = { 'QA_RUNTIME_SCENARIO_ATTRIBUTES' => '{"parallel":true}' })
    cmd = "bundle exec parallel_test -t rspec --combine-stderr --serialize-stdout -- #{arguments.join(' ')}"
    expect(Open3).to receive(:popen2e)
      .with(hash_including(env), cmd)
      .and_return(0)
  end
end