Class: Gitlab::QA::Component::Specs

Inherits:
Scenario::Template show all
Defined in:
lib/gitlab/qa/component/specs.rb

Overview

This class represents GitLab QA specs image that is implemented in the ‘qa/` directory located in GitLab CE / EE repositories.

Constant Summary collapse

LAST_RUN_FILE =
"examples.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Scenario::Template

perform

Constructor Details

#initializeSpecs

Returns a new instance of Specs.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/qa/component/specs.rb', line 30

def initialize
  @docker = Docker::Engine.new(stream_output: true) # stream test output directly instead of through logger
  @env = {}
  @volumes = {}
  @additional_hosts = []
  @volumes = { '/var/run/docker.sock' => '/var/run/docker.sock' }
  @retry_failed_specs = Runtime::Env.retry_failed_specs?

  include_optional_volumes(
    Runtime::Env.qa_rspec_report_path => 'rspec',
    Runtime::Env.qa_knapsack_report_path => 'knapsack'
  )
end

Instance Attribute Details

#additional_hostsObject

Returns the value of attribute additional_hosts.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def additional_hosts
  @additional_hosts
end

#argsObject

Returns the value of attribute args.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def args
  @args
end

#envObject

Returns the value of attribute env.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def env
  @env
end

#hostnameObject

Returns the value of attribute hostname.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def hostname
  @hostname
end

#infer_qa_image_from_releaseObject

Returns the value of attribute infer_qa_image_from_release.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def infer_qa_image_from_release
  @infer_qa_image_from_release
end

#networkObject

Returns the value of attribute network.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def network
  @network
end

#releaseObject

Returns the value of attribute release.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def release
  @release
end

#retry_failed_specsObject

Returns the value of attribute retry_failed_specs.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def retry_failed_specs
  @retry_failed_specs
end

#runner_networkObject

Returns the value of attribute runner_network.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def runner_network
  @runner_network
end

#suiteObject

Returns the value of attribute suite.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def suite
  @suite
end

#volumesObject

Returns the value of attribute volumes.



18
19
20
# File 'lib/gitlab/qa/component/specs.rb', line 18

def volumes
  @volumes
end

Instance Method Details

#internal_performObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gitlab/qa/component/specs.rb', line 57

def internal_perform
  return Runtime::Logger.info("Skipping tests.") if skip_tests?

  raise ArgumentError unless [suite, release].all?

  docker_pull_qa_image_if_needed

  Runtime::Logger.info("Running test suite `#{suite}` for #{release.project_name}")

  name = "#{release.project_name}-qa-#{SecureRandom.hex(4)}"
  run_specs(name)
rescue Support::ShellCommand::StatusError => e
  raise e unless retry_failed_specs

  Runtime::Logger.warn("Initial test run failed, attempting to retry failed specs in new process!")
  results_file = File.join(host_artifacts_dir(name), LAST_RUN_FILE)
  raise e unless valid_last_run_file?(results_file)

  Runtime::Logger.debug("Found initial run results file '#{results_file}', retrying failed specs!")
  run_specs(name, retry_process: true, initial_run_results_host_path: results_file)
end

#performObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/qa/component/specs.rb', line 44

def perform
  if Runtime::Env.use_selenoid?
    Component::Selenoid.perform do |selenoid|
      selenoid.network = network
      selenoid.instance do
        internal_perform
      end
    end
  else
    internal_perform
  end
end