zeus-parallel_tests 0.1.1 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a9ddfc02ea9f897dbb022adf3a43dcb754d3382
4
- data.tar.gz: 667d9c3efa43f7e9e247aafba77209afb737039a
3
+ metadata.gz: defcebae997e5144a3de67c7dfdf79a7a1c99006
4
+ data.tar.gz: a3678f055ac0a432fb77181217b6e81b79db3bc0
5
5
  SHA512:
6
- metadata.gz: fd52aee09d6bf030dc18e4441c2c5e379d9560499f578e18ef82d09f6716298e40ed68193f6c7f56d8715b1260b26881a5d171e29f8a140cf01f6d960cb5751c
7
- data.tar.gz: 1d04a157c8eb309219b90eba4bb3bedc9aa023d11830374375cad92da9f228530fb006c070dbdb3dd18d62a26dcfd41d9c36790ce5c91604dbd0acb56dfa2e72
6
+ metadata.gz: 3d8924e1842bda6494c16b2a1d05f74c5030902a00b623fe49c97ba5f5590d6e6d0d4e1d468602260e0c8fc871763d1fe64e38e8108d154734dd0f61eb89f0e2
7
+ data.tar.gz: 5902643045dbd7750e906373cb4167588d14fa8dc9071cb79b1703a5a40cf717661f1cb81f12b27dac42aaf64b899c0f17e3f455a9fad3312d1265d4796041b9
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: bundle exec rake travis:test
data/README.md CHANGED
@@ -1,6 +1,67 @@
1
1
  # Zeus::ParallelTests
2
2
 
3
- TODO: Write a gem description
3
+ [![Build Status](https://travis-ci.org/sevos/zeus-parallel_tests.png?branch=master)](https://travis-ci.org/sevos/zeus-parallel_tests)
4
+ [![Dependency Status](https://gemnasium.com/sevos/zeus-parallel_tests.png)](https://gemnasium.com/sevos/zeus-parallel_tests)
5
+
6
+ [Zeus](https://github.com/burke/zeus) is a tool for speeding up your tests by preloading a Rails app.
7
+ [parallel_tests](https://github.com/grosser/parallel_tests) also speeds up your tests by running them, well,
8
+ in parallel. Two good gems, so why not to use them together? Let's make our CPUs sweat!
9
+
10
+ ## Show me the numbers!
11
+
12
+ ### RSpec
13
+
14
+ ```
15
+ $ time rspec spec
16
+
17
+ ...
18
+
19
+ Finished in 1 minute 8.34 seconds
20
+ 916 examples, 0 failures
21
+
22
+ real 1m21.480s
23
+ user 1m4.805s
24
+ sys 0m4.516s
25
+ ```
26
+
27
+ ### parallel_tests
28
+
29
+ ```
30
+ $ time rake parallel:spec[8]
31
+ Using recorded test runtime
32
+ 8 processes for 141 specs, ~ 17 specs per process
33
+
34
+ ...
35
+
36
+ 916 examples, 0 failures
37
+
38
+ Took 46.626499 seconds
39
+
40
+ real 0m55.790s
41
+ user 4m3.065s
42
+ sys 0m32.160s
43
+ ```
44
+
45
+ ### Zeus+parallel_tests
46
+
47
+ ```
48
+ $ time zeus rake parallel:spec[8]
49
+ Developer helpers loaded
50
+ Using recorded test runtime
51
+ 8 processes for 141 specs, ~ 17 specs per process
52
+
53
+ ...
54
+
55
+ 916 examples, 0 failures
56
+
57
+ Took 26.610327 seconds
58
+
59
+ real 0m28.514s
60
+ user 0m0.732s
61
+ sys 0m0.061s
62
+ ```
63
+
64
+ Ready to go?
4
65
 
5
66
  ## Installation
6
67
 
@@ -12,13 +73,47 @@ And then execute:
12
73
 
13
74
  $ bundle
14
75
 
15
- Or install it yourself as:
76
+ You need also to initialize your project with custom Zeus plan:
77
+
78
+ $ zeus-parallel_tests init
79
+
80
+ This will create two files in your project:
16
81
 
17
- $ gem install zeus-parallel_tests
82
+ * custom_plan.rb
83
+ * zeus.json
84
+
85
+ ### RVM
86
+
87
+ For RVM users it is recommended to install rvm-bundler gem.
18
88
 
19
89
  ## Usage
20
90
 
21
- TODO: Write usage instructions here
91
+ First [follow instructions](https://github.com/grosser/parallel_tests) and prepare
92
+ your application to use parallel_tests.
93
+
94
+ Launch another terminal and run zeus' master process:
95
+
96
+ $ bundle exec zeus start
97
+
98
+ Then you can run your parallel specs:
99
+
100
+ $ zeus parallel_rspec spec
101
+
102
+ or your cucumbers:
103
+
104
+ $ zeus parallel_cucumber features
105
+
106
+ ## What is supported?
107
+
108
+ * rspec
109
+ * cucumber
110
+
111
+ ## TODO
112
+
113
+ * smoke tests
114
+ * minitest support
115
+ * cucumber support
116
+ * guard-rspec <del>(just pass `zeus: true` and `parallel: true` into configuration hash)</del>
22
117
 
23
118
  ## Contributing
24
119
 
data/Rakefile CHANGED
@@ -1 +1,20 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs.push "lib"
8
+ t.test_files = FileList[File.expand_path('../test/**/*_test.rb', __FILE__)]
9
+ t.verbose = true
10
+ end
11
+
12
+
13
+ namespace :travis do
14
+ Rake::TestTask.new do |t|
15
+ t.libs.push "lib"
16
+ t.test_files = FileList[File.expand_path('../test/**/*_test.rb', __FILE__)] -
17
+ FileList[File.expand_path('../test/slow/*_test.rb', __FILE__)]
18
+ t.verbose = true
19
+ end
20
+ end
@@ -8,7 +8,7 @@ unless ARGV == ["init"]
8
8
  exit 1
9
9
  end
10
10
 
11
- def copy(file, target_dir, mode = 0644)
11
+ def copy(file, target_dir)
12
12
  templates_dir = File.expand_path("../../lib/zeus/parallel_tests/templates/", __FILE__)
13
13
  source_file = File.join(templates_dir, file)
14
14
  dest_file = File.join(File.expand_path(target_dir), file)
@@ -20,9 +20,7 @@ def copy(file, target_dir, mode = 0644)
20
20
  end
21
21
  end
22
22
  FileUtils.cp(source_file, dest_file)
23
- FileUtils.chmod(mode, dest_file)
24
23
  end
25
24
 
26
25
  copy "custom_plan.rb", "./"
27
26
  copy "zeus.json", "./"
28
- copy "spec", "script/", 0755
@@ -1,12 +1,69 @@
1
+ require_relative '../parallel_tests'
2
+ require_relative 'worker'
3
+
1
4
  module Zeus
2
5
  module ParallelTests
3
6
  class Rails < ::Zeus::Rails
7
+ def parallel_cucumber
8
+ exec parallel_runner_command "cucumber", ARGV
9
+ end
10
+
4
11
  def parallel_rspec
5
- argv = ARGV.dup
6
- test_env_number = argv.shift
12
+ exec parallel_runner_command "rspec", ARGV
13
+ end
14
+
15
+ def parallel_cucumber_worker
16
+ spawn_slave { |args| cucumber(args) }
17
+ end
18
+
19
+ def parallel_rspec_worker
20
+ spawn_slave { |args| test(["--color", "--tty", *args]) }
21
+ end
22
+
23
+ # Patches required in Zeus
24
+
25
+ def test(argv = ARGV)
26
+ if spec_file?(argv) && defined?(RSpec)
27
+ # disable autorun in case the user left it in spec_helper.rb
28
+ RSpec::Core::Runner.disable_autorun!
29
+ exit RSpec::Core::Runner.run(argv)
30
+ else
31
+ Zeus::M.run(argv)
32
+ end
33
+ end
34
+
35
+ def cucumber(argv = ARGV)
36
+ cucumber_main = Cucumber::Cli::Main.new(argv.dup)
37
+ had_failures = cucumber_main.execute!(@cucumber_runtime)
38
+ exit_code = had_failures ? 1 : 0
39
+ exit exit_code
40
+ end
41
+
42
+ # End of patches for Zeus
43
+
44
+ private
45
+
46
+ def parallel_runner_command(suite, argv)
47
+ env_slave_path = %[PARALLEL_TESTS_EXECUTABLE='#{Worker.command suite}']
48
+ "#{env_slave_path} parallel_#{suite} #{argv.join ' '}"
49
+ end
50
+
51
+ def spawn_slave
52
+ worker, workers_count, args_file = ARGV
7
53
  # Parallels spec reuse main test db instead of db with "1" appended
8
- test_env_number = nil if test_env_number == "1"
54
+ ENV['TEST_ENV_NUMBER'] = test_env_number = (worker == "1" ? nil : worker)
55
+ ENV['PARALLEL_TEST_GROUPS'] = workers_count
56
+
57
+ reconfigure_activerecord test_env_number
58
+
59
+ yield load_args_from_file(args_file)
60
+ end
9
61
 
62
+ def load_args_from_file(path)
63
+ File.readlines(path).map(&:chomp)
64
+ end
65
+
66
+ def reconfigure_activerecord(test_env_number)
10
67
  return unless defined?(ActiveRecord::Base)
11
68
  begin
12
69
  ActiveRecord::Base.clear_all_connections!
@@ -15,31 +72,13 @@ module Zeus
15
72
  config[:database] = "#{config[:database]}#{test_env_number}"
16
73
 
17
74
  ActiveRecord::Base.establish_connection(config)
75
+ puts "Connecting to #{ActiveRecord::Base.connection_config[:database]}"
18
76
  if ActiveRecord::Base.respond_to?(:shared_connection)
19
77
  ActiveRecord::Base.shared_connection = ActiveRecord::Base.retrieve_connection
20
78
  end
21
79
  rescue ActiveRecord::AdapterNotSpecified
22
80
  end
23
-
24
- ENV['TEST_ENV_NUMBER'] = test_env_number
25
- ENV['PARALLEL_TEST_GROUPS'] = argv.shift
26
-
27
- rspec_args_file = argv.shift
28
- test_files = File.readlines(rspec_args_file).map(&:chomp)
29
-
30
- test(test_files.unshift("--colour").unshift("--tty"))
31
- end
32
-
33
- def test(argv = ARGV)
34
- if spec_file?(argv) && defined?(RSpec)
35
- # disable autorun in case the user left it in spec_helper.rb
36
- RSpec::Core::Runner.disable_autorun!
37
- exit RSpec::Core::Runner.run(argv)
38
- else
39
- Zeus::M.run(argv)
40
- end
41
81
  end
42
-
43
82
  end
44
83
  end
45
84
  end
@@ -11,13 +11,18 @@
11
11
  "server": ["s"],
12
12
  "generate": ["g"],
13
13
  "destroy": ["d"],
14
- "dbconsole": []
14
+ "dbconsole": [],
15
+ "parallel_rspec": [],
16
+ "parallel_cucumber": []
15
17
  },
16
18
  "test_environment": {
17
- "cucumber_environment": {"cucumber": []},
19
+ "cucumber_environment": {
20
+ "cucumber": [],
21
+ "parallel_cucumber_worker": []
22
+ },
18
23
  "test_helper": {
19
24
  "test": ["rspec", "testrb"],
20
- "parallel_rspec": []
25
+ "parallel_rspec_worker": []
21
26
  }
22
27
  }
23
28
  }
@@ -1,5 +1,5 @@
1
1
  module Zeus
2
2
  module ParallelTests
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0.beta1"
4
4
  end
5
5
  end
@@ -0,0 +1,51 @@
1
+ require_relative '../parallel_tests'
2
+ require 'tempfile'
3
+
4
+ module Zeus::ParallelTests
5
+ class Worker
6
+ def self.command(suite)
7
+ "ruby #{__FILE__} #{suite}"
8
+ end
9
+
10
+ def initialize(suite, env, argv)
11
+ @env = env
12
+ @argv = argv
13
+ @suite = suite
14
+ end
15
+
16
+ def call
17
+ system %{zeus parallel_#{@suite}_worker #{parallel_tests_attributes}}
18
+ args_file.unlink
19
+ $?.to_i
20
+ end
21
+
22
+ private
23
+
24
+ def parallel_tests_attributes
25
+ [test_env_number.to_s,
26
+ @env['PARALLEL_TEST_GROUPS'],
27
+ args_file.path].join(' ')
28
+ end
29
+
30
+ def args_file
31
+ @args_file ||= begin
32
+ Tempfile.new("rspec_args").tap do |file|
33
+ @argv.each do |arg|
34
+ file.puts arg
35
+ end
36
+ file.close
37
+ end
38
+ end
39
+ end
40
+
41
+ def test_env_number
42
+ @env['TEST_ENV_NUMBER'] != "" && @env['TEST_ENV_NUMBER'] || 1
43
+ end
44
+ end
45
+ end
46
+
47
+ if $PROGRAM_NAME == __FILE__
48
+ argv = ARGV.dup
49
+ exit Zeus::ParallelTests::Worker.new(argv.shift, ENV, argv).call.to_i
50
+ end
51
+
@@ -0,0 +1,9 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ require 'zeus/parallel_tests'
4
+
5
+ describe "zeus-parallel_tests" do
6
+ it 'should be tested' do
7
+ skip("any ideas how to test this?")
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+
5
+ describe 'zeus-parallel_tests' do
6
+ before do
7
+ @project_dir = File.expand_path(Dir.mktmpdir)
8
+ Dir.mkdir(File.join(@project_dir, "script"))
9
+
10
+ bin = File.expand_path('../../../bin/zeus-parallel_tests', __FILE__)
11
+ @run = -> { system("#{bin} init &>/dev/null", chdir: @project_dir) }
12
+ end
13
+
14
+ after do
15
+ FileUtils.rm_rf @project_dir
16
+ @io && @io.close
17
+ end
18
+
19
+ it "creates zeus configuration and script/spec in projects directory" do
20
+ @run.call
21
+
22
+ expected_files = ['zeus.json', 'custom_plan.rb'].
23
+ map { |f| File.join(@project_dir, f) }
24
+
25
+ expected_files.each do |f|
26
+ assert File.exists?(f), "#{f} should exists"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ ENV["TEST"] = 'true'
2
+ require 'rubygems'
3
+ require 'minitest/autorun'
4
+ $:.unshift File.expand_path("../../lib")
5
+ require 'zeus/parallel_tests'
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "zeus", "~> 0.13.3"
22
- spec.add_dependency "parallel_tests", "0.10.3"
22
+ spec.add_dependency "parallel_tests", "~> 0.10.4"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeus-parallel_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Roszczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-23 00:00:00.000000000 Z
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeus
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: parallel_tests
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.3
33
+ version: 0.10.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.3
40
+ version: 0.10.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,24 +70,28 @@ description: Integration for zeus and parallel_tests
70
70
  email:
71
71
  - artur.roszczyk@gmail.com
72
72
  executables:
73
- - zeus-parallel_specs
73
+ - zeus-parallel_tests
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - .gitignore
78
78
  - .ruby-gemset
79
79
  - .ruby-version
80
+ - .travis.yml
80
81
  - Gemfile
81
82
  - LICENSE.txt
82
83
  - README.md
83
84
  - Rakefile
84
- - bin/zeus-parallel_specs
85
+ - bin/zeus-parallel_tests
85
86
  - lib/zeus/parallel_tests.rb
86
87
  - lib/zeus/parallel_tests/rails.rb
87
88
  - lib/zeus/parallel_tests/templates/custom_plan.rb
88
- - lib/zeus/parallel_tests/templates/spec
89
89
  - lib/zeus/parallel_tests/templates/zeus.json
90
90
  - lib/zeus/parallel_tests/version.rb
91
+ - lib/zeus/parallel_tests/worker.rb
92
+ - test/integration_test.rb
93
+ - test/slow/zeus-parallel_tests_test.rb
94
+ - test/test_helper.rb
91
95
  - zeus-parallel_tests.gemspec
92
96
  homepage: ''
93
97
  licenses:
@@ -104,13 +108,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
108
  version: '0'
105
109
  required_rubygems_version: !ruby/object:Gem::Requirement
106
110
  requirements:
107
- - - '>='
111
+ - - '>'
108
112
  - !ruby/object:Gem::Version
109
- version: '0'
113
+ version: 1.3.1
110
114
  requirements: []
111
115
  rubyforge_project:
112
116
  rubygems_version: 2.0.3
113
117
  signing_key:
114
118
  specification_version: 4
115
119
  summary: ''
116
- test_files: []
120
+ test_files:
121
+ - test/integration_test.rb
122
+ - test/slow/zeus-parallel_tests_test.rb
123
+ - test/test_helper.rb
124
+ has_rdoc:
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'tempfile'
3
-
4
- test_env_number = ENV['TEST_ENV_NUMBER'] || 1
5
- test_env_number = 1 if test_env_number == ""
6
-
7
- rspec_args_file = Tempfile.new("rspec_args")
8
- ARGV.each do |arg|
9
- rspec_args_file.puts arg
10
- end
11
-
12
- rspec_args_file.close
13
-
14
- system %{zeus parallel_rspec #{test_env_number} #{ENV['PARALLEL_TEST_GROUPS']} #{rspec_args_file.path}}
15
- status = $?
16
-
17
- rspec_args_file.unlink
18
-
19
- exit status.to_i