Merge pull request #11 from chef/concurrent-integrationtest

Concurrent integrationtest
This commit is contained in:
Christoph Hartmann 2015-09-14 09:23:49 +02:00 committed by Dominik Richter
commit 80f421e67e
3 changed files with 33 additions and 24 deletions

View file

@ -9,9 +9,6 @@ require 'vulcano/profile_context'
# spec requirements
require 'rspec'
require 'rspec/its'
require 'specinfra'
require 'specinfra/helper'
require 'specinfra/helper/set'
require 'vulcano/rspec_json_formatter'
module Vulcano
@ -20,9 +17,7 @@ module Vulcano
@rules = []
@profile_id = profile_id
@conf = Vulcano::Backend.target_config(normalize_map(conf))
# global reset
RSpec.world.reset
@tests = RSpec::Core::World.new
configure_output
configure_backend
@ -37,8 +32,6 @@ module Vulcano
end
def configure_output
# RSpec.configuration.output_stream = $stdout
# RSpec.configuration.error_stream = $stderr
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
end
@ -95,14 +88,17 @@ module Vulcano
end
set_rspec_ids(example, rule_id)
RSpec.world.register(example)
@tests.register(example)
end
end
end
def run
rspec_runner = RSpec::Core::Runner.new(nil)
rspec_runner.run_specs(RSpec.world.ordered_example_groups)
run_with(RSpec::Core::Runner.new(nil))
end
def run_with(rspec_runner)
rspec_runner.run_specs(@tests.ordered_example_groups)
end
def set_rspec_ids(example, id)

View file

@ -2,6 +2,7 @@
require 'docker'
require 'yaml'
require 'concurrent'
require_relative '../lib/vulcano'
tests = ARGV
@ -20,10 +21,21 @@ class DockerTester
def run
puts ['Running tests:', @tests].flatten.join("\n- ")
puts ''
rspec_runner = RSpec::Core::Runner.new(nil)
# test all images
@conf['images'].each do |n|
test_image(n)
end.all? or fail 'Test failures'
promises = @conf['images'].map { |n|
Concurrent::Promise.new {
container = prepare_image(n)
runner = test_container(container.id)
res = runner.run_with(rspec_runner)
stop_container(container)
res
}.execute
}
sleep(0.1) until promises.all?(&:fulfilled?)
promises.map(&:value).all? or fail 'Test failures'
end
def docker_images_by_tag
@ -45,32 +57,32 @@ class DockerTester
end
def test_container(container_id)
opts = { 'target' => "specinfra+docker://#{container_id}" }
puts "--> run test on docker #{container_id}"
opts = { 'target' => "docker://#{container_id}" }
runner = Vulcano::Runner.new(nil, opts)
runner.add_tests(@tests)
runner.run
runner
end
def test_image(name)
def prepare_image(name)
dname = "docker-#{name}:latest"
image = @images[dname]
fail "Can't find docker image #{dname}" if image.nil?
puts "--> start docker #{name}"
container = Docker::Container.create(
'Cmd' => %w{ /bin/bash },
'Cmd' => ['/bin/bash'],
'Image' => image.id,
'OpenStdin' => true
'OpenStdin' => true,
)
container.start
container
end
puts "--> run test on docker #{name}"
res = test_container(container.id)
puts "--> killrm docker #{name}"
def stop_container(container)
puts "--> killrm docker #{container.id}"
container.kill
container.delete(force: true)
res
end
end

View file

@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry', '~> 0.10'
spec.add_development_dependency 'rubocop', '~> 0.33.0'
spec.add_development_dependency 'simplecov', '~> 0.10'
spec.add_development_dependency 'concurrent-ruby', '~> 0.9'
spec.add_dependency 'thor', '~> 0.19'
spec.add_dependency 'json', '~> 1.8'