moxiesoft_parallel_tests 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,110 @@
1
+ # ---- requirements
2
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
3
+ require 'rubygems'
4
+
5
+ FAKE_RAILS_ROOT = '/tmp/pspecs/fixtures'
6
+
7
+ require 'parallel_specs'
8
+ require 'parallel_cucumber'
9
+
10
+ def mocked_process
11
+ open('|cat /dev/null')
12
+ end
13
+
14
+ def size_of(group)
15
+ group.inject(0) { |sum, test| sum += File.stat(test).size }
16
+ end
17
+
18
+ # Uses /tmp/parallel_tests/application as the cwd so we can create and remove
19
+ # files as we want to. After execution it changes cwd back to the original one.
20
+ def use_temporary_directory_for
21
+ require 'fileutils'
22
+
23
+ dir = File.join("/tmp", "parallel_tests")
24
+ new_dir = File.join(dir, "application")
25
+
26
+ begin
27
+ # just in case the temporary dir already exists
28
+ FileUtils.rm_rf(dir) if File.exists?(dir)
29
+
30
+ # create the temporary directory
31
+ FileUtils.mkdir_p(new_dir)
32
+
33
+ # chdir changes cwd back to the original one after it is done
34
+ Dir.chdir(new_dir) do
35
+ yield
36
+ end
37
+ ensure
38
+ FileUtils.rm_rf(dir) if File.exists?(dir)
39
+ end
40
+ end
41
+
42
+ def test_tests_in_groups(klass, folder, suffix)
43
+ test_root = "#{FAKE_RAILS_ROOT}/#{folder}"
44
+
45
+ describe :tests_in_groups do
46
+ before :all do
47
+ system "rm -rf #{FAKE_RAILS_ROOT}; mkdir -p #{test_root}/temp"
48
+
49
+ @files = [0,1,2,3,4,5,6,7].map do |i|
50
+ size = 99
51
+ file = "#{test_root}/temp/x#{i}#{suffix}"
52
+ File.open(file, 'w') { |f| f.puts 'x' * size }
53
+ file
54
+ end
55
+
56
+ @log = "#{FAKE_RAILS_ROOT}/tmp/parallel_profile.log"
57
+ `mkdir #{File.dirname(@log)}`
58
+ `rm -f #{@log}`
59
+ end
60
+
61
+ it "groups when given an array of files" do
62
+ list_of_files = Dir["#{test_root}/**/*#{suffix}"]
63
+ found = klass.tests_with_runtime(list_of_files)
64
+ found.should =~ list_of_files.map{ |file| [file, File.stat(file).size]}
65
+ end
66
+
67
+ it "finds all tests" do
68
+ found = klass.tests_in_groups(test_root, 1)
69
+ all = [ Dir["#{test_root}/**/*#{suffix}"] ]
70
+ (found.flatten - all.flatten).should == []
71
+ end
72
+
73
+ it "partitions them into groups by equal size" do
74
+ groups = klass.tests_in_groups(test_root, 2)
75
+ groups.map{|g| size_of(g)}.should == [400, 400]
76
+ end
77
+
78
+ it 'should partition correctly with a group size of 4' do
79
+ groups = klass.tests_in_groups(test_root, 4)
80
+ groups.map{|g| size_of(g)}.should == [200, 200, 200, 200]
81
+ end
82
+
83
+ it 'should partition correctly with an uneven group size' do
84
+ groups = klass.tests_in_groups(test_root, 3)
85
+ groups.map{|g| size_of(g)}.should =~ [300, 300, 200]
86
+ end
87
+
88
+ it "partitions by runtime when runtime-data is available" do
89
+ File.open(@log,'w') do |f|
90
+ @files[1..-1].each{|file| f.puts "#{file}:#{@files.index(file)}"}
91
+ f.puts "#{@files[0]}:10"
92
+ end
93
+
94
+ groups = klass.tests_in_groups(test_root, 2)
95
+ groups.size.should == 2
96
+ # 10 + 5 + 3 + 1 = 19
97
+ groups[0].should == [@files[0],@files[5],@files[3],@files[1]]
98
+ # 7 + 6 + 4 + 2 = 19
99
+ groups[1].should == [@files[7],@files[6],@files[4],@files[2]]
100
+ end
101
+
102
+ it "partitions by round-robin when not sorting" do
103
+ files = ["file1.rb", "file2.rb", "file3.rb", "file4.rb"]
104
+ klass.should_receive(:find_tests).and_return(files)
105
+ groups = klass.tests_in_groups(files, 2, :no_sort => true)
106
+ groups[0].should == ["file1.rb", "file3.rb"]
107
+ groups[1].should == ["file2.rb", "file4.rb"]
108
+ end
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moxiesoft_parallel_tests
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 12
9
+ version: 0.4.12
10
+ platform: ruby
11
+ authors:
12
+ - Michael Grosser
13
+ - Eric DeBill
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-07 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: parallel
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description:
35
+ email: grosser.michael@gmail.com
36
+ executables:
37
+ - parallel_cucumber
38
+ - parallel_spec
39
+ - parallel_test
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - Rakefile
49
+ - Readme.md
50
+ - VERSION
51
+ - bin/parallel_cucumber
52
+ - bin/parallel_spec
53
+ - bin/parallel_test
54
+ - lib/parallel_cucumber.rb
55
+ - lib/parallel_specs.rb
56
+ - lib/parallel_specs/spec_runtime_logger.rb
57
+ - lib/parallel_tests.rb
58
+ - lib/parallel_tests/grouper.rb
59
+ - lib/parallel_tests/railtie.rb
60
+ - lib/parallel_tests/tasks.rb
61
+ - lib/tasks/parallel_tests.rake
62
+ - spec/integration_spec.rb
63
+ - spec/parallel_cucumber_spec.rb
64
+ - spec/parallel_specs_spec.rb
65
+ - spec/parallel_tests_spec.rb
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/edebill-moxiesoft/moxiesoft_parallel_tests
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Run tests / specs / features in parallel
99
+ test_files:
100
+ - spec/integration_spec.rb
101
+ - spec/parallel_cucumber_spec.rb
102
+ - spec/parallel_specs_spec.rb
103
+ - spec/parallel_tests_spec.rb
104
+ - spec/spec_helper.rb