Skip to content

Commit 76b19c6

Browse files
committed
add parallel testing
1 parent 19c66f1 commit 76b19c6

30 files changed

+97
-124
lines changed

.rspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
--format documentation
1+
--format progress
22
--color
33
--require spec_helper

kanrisuru.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
1414

1515
gem.required_ruby_version = '>= 2.5.0'
1616

17+
gem.add_development_dependency 'parallel_tests', '~> 3.7'
1718
gem.add_development_dependency 'rspec', '~> 3.10'
1819
gem.add_development_dependency 'rubocop', '~> 1.12'
1920
gem.add_development_dependency 'rubocop-rspec', '~> 2.2'

spec/functional/core/archive_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Apt do
5+
RSpec.describe Kanrisuru::Core::Archive do
66
before(:all) do
77
StubNetwork.stub!
88
StubNetwork.stub_command!(:realpath) do |_args|
@@ -141,6 +141,7 @@
141141
%w[diff compare d].each do |action_variant|
142142
expect_command(host.tar(action_variant, 'archive.tar', directory: directory),
143143
'tar --restrict -C /home/ubuntu/dir -f archive.tar -d')
144+
144145
expect_command(host.tar(action_variant, 'archive.tar',
145146
directory: directory,
146147
occurrence: 4),

spec/helper/stub_network.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def execute_with_retries(command)
3333
end
3434

3535
return if Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36-
36+
3737
Kanrisuru::Result.class_eval do
3838
alias_method :initialize_alias, :initialize
3939
def initialize(command, parse_result = false, &block)

spec/helper/test_hosts.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
# frozen_string_literal: true
22

3+
require 'securerandom'
4+
35
class TestHosts
46
class << self
57
def each_os(opts = {}, &block)
68
%w[debian ubuntu fedora centos rhel opensuse sles].each do |os_name|
79
next unless test?(os_name)
810
next if opts[:only] && !only?(opts, os_name)
911

10-
block.call(os_name)
12+
host_json = TestHosts.host(os_name)
13+
spec_dir = spec_dir(os_name, host_json)
14+
15+
block.call(os_name, host_json, spec_dir)
1116
end
1217
end
1318

1419
def host(name)
1520
hosts(name)
1621
end
1722

23+
def spec_dir(os_name, host_json)
24+
random_string = SecureRandom.hex
25+
"#{host_json['home']}/.kanrisuru_spec_files_#{random_string[0..5]}"
26+
end
27+
1828
def only?(opts, name)
1929
((opts[:only].instance_of?(Array) && opts[:only].include?(name)) ||
2030
(opts[:only].instance_of?(String) && opts[:only] == name))

spec/integration/core/apt_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Apt do
6-
TestHosts.each_os(only: %w[debian ubuntu]) do |os_name|
5+
TestHosts.each_os(only: %w[debian ubuntu]) do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Apt do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/archive_spec.rb

+8-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Archive do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json, spec_dir|
6+
RSpec.describe Kanrisuru::Core::Archive do
77
context "with #{os_name}" do
88
before(:all) do
9-
host_json = TestHosts.host(os_name)
109
host = Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],
1211
username: host_json['username'],
1312
keys: [host_json['ssh_key']]
1413
)
1514

16-
host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15+
host.mkdir(spec_dir, silent: true)
1716
host.disconnect
1817
end
1918

20-
let(:host_json) { TestHosts.host(os_name) }
2119
let(:host) do
2220
Kanrisuru::Remote::Host.new(
2321
host: host_json['hostname'],
@@ -26,22 +24,19 @@
2624
)
2725
end
2826

29-
let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30-
3127
after do
3228
host.disconnect
3329
end
3430

3531
after(:all) do
36-
host_json = TestHosts.host(os_name)
3732
host = Kanrisuru::Remote::Host.new(
3833
host: host_json['hostname'],
3934
username: host_json['username'],
4035
keys: [host_json['ssh_key']]
4136
)
4237

43-
host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44-
host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
38+
host.rmdir(spec_dir)
39+
host.rmdir("#{spec_dir}/extract-tar-files") if host.dir?("#{spec_dir}/extract-tar-files")
4540
host.disconnect
4641
end
4742

@@ -126,10 +121,10 @@
126121
paths = result.map(&:path)
127122
expect(paths.include?('test2.config')).to eq(false)
128123

129-
host.mkdir("#{host_json['home']}/extract-tar-files", silent: true)
130-
host.tar('extract', 'archive.tar', directory: "#{host_json['home']}/extract-tar-files")
124+
host.mkdir("#{spec_dir}/extract-tar-files", silent: true)
125+
host.tar('extract', 'archive.tar', directory: "#{spec_dir}/extract-tar-files")
131126

132-
result = host.ls(path: "#{host_json['home']}/extract-tar-files")
127+
result = host.ls(path: "#{spec_dir}/extract-tar-files")
133128
paths = result.map(&:path)
134129

135130
expect(paths.include?('test1.config')).to eq(true)

spec/integration/core/disk_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Disk do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Disk do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/dmi_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Dmi do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Dmi do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/file_spec.rb

+4-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::File do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json, spec_dir|
6+
RSpec.describe Kanrisuru::Core::File do
77
context "with #{os_name}" do
88
before(:all) do
9-
host_json = TestHosts.host(os_name)
109
host = Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],
1211
username: host_json['username'],
1312
keys: [host_json['ssh_key']]
1413
)
1514

16-
host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15+
host.mkdir(spec_dir, silent: true)
1716
host.disconnect
1817
end
1918

20-
let(:host_json) { TestHosts.host(os_name) }
2119
let(:host) do
2220
Kanrisuru::Remote::Host.new(
2321
host: host_json['hostname'],
@@ -26,25 +24,18 @@
2624
)
2725
end
2826

29-
let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30-
3127
after do
3228
host.disconnect
3329
end
3430

3531
after(:all) do
36-
host_json = TestHosts.host(os_name)
3732
host = Kanrisuru::Remote::Host.new(
3833
host: host_json['hostname'],
3934
username: host_json['username'],
4035
keys: [host_json['ssh_key']]
4136
)
4237

43-
host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
44-
if host.dir?("#{host_json['home']}/extract-tar-files")
45-
host.rm("#{host_json['home']}/extract-tar-files", force: true,
46-
recursive: true)
47-
end
38+
host.rm(spec_dir, force: true, recursive: true)
4839
host.disconnect
4940
end
5041

spec/integration/core/find_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Find do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Find do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/group_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Group do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Group do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/ip_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::IP do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::IP do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/path_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Path do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Path do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/socket_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Socket do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Socket do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
9-
108
let(:host) do
119
Kanrisuru::Remote::Host.new(
1210
host: host_json['hostname'],

spec/integration/core/stat_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::Stat do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::Stat do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

spec/integration/core/stream_spec.rb

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe Kanrisuru::Core::Stream do
4-
TestHosts.each_os do |os_name|
3+
require 'spec_helper'
4+
5+
TestHosts.each_os do |os_name, host_json, spec_dir|
6+
RSpec.describe Kanrisuru::Core::Stream do
57
context "with #{os_name}" do
68
before(:all) do
7-
host_json = TestHosts.host(os_name)
89
host = Kanrisuru::Remote::Host.new(
910
host: host_json['hostname'],
1011
username: host_json['username'],
1112
keys: [host_json['ssh_key']]
1213
)
1314

14-
host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15+
host.mkdir(spec_dir, silent: true)
1516
host.disconnect
1617
end
1718

18-
let(:host_json) { TestHosts.host(os_name) }
1919
let(:host) do
2020
Kanrisuru::Remote::Host.new(
2121
host: host_json['hostname'],
@@ -24,21 +24,18 @@
2424
)
2525
end
2626

27-
let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
28-
2927
after do
3028
host.disconnect
3129
end
3230

3331
after(:all) do
34-
host_json = TestHosts.host(os_name)
3532
host = Kanrisuru::Remote::Host.new(
3633
host: host_json['hostname'],
3734
username: host_json['username'],
3835
keys: [host_json['ssh_key']]
3936
)
4037

41-
host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
38+
host.rmdir(spec_dir)
4239
host.disconnect
4340
end
4441

spec/integration/core/system_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Kanrisuru::Core::System do
6-
TestHosts.each_os do |os_name|
5+
TestHosts.each_os do |os_name, host_json|
6+
RSpec.describe Kanrisuru::Core::System do
77
context "with #{os_name}" do
8-
let(:host_json) { TestHosts.host(os_name) }
98
let(:host) do
109
Kanrisuru::Remote::Host.new(
1110
host: host_json['hostname'],

0 commit comments

Comments
 (0)