semaphore_test_boosters 0.3.0 → 0.4.0

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: de95c3faf8fec6fe5d037d492da9433df3028fa2
4
- data.tar.gz: adbee1c687caf014f5145248b6994001365aa61c
3
+ metadata.gz: 19d8e45b1a80f42a4c02d663029c796a6f96151b
4
+ data.tar.gz: c3a59300fe1bca57b29528310ae48968a11c1fda
5
5
  SHA512:
6
- metadata.gz: e3f19dac14a29900d51795f3ed105d70df9f09e4b983b6b78e395bae78d3e18af953b9005a7aa649764be2ad247390dea88d57d6da46a08f8566fe1b4393cc3c
7
- data.tar.gz: 7e70e1209987c81c4a92c5d102ad82966e8fc634985f48f81c04da28938f69ac6f0dcf5dedc8e642c14aa02eb7d7c3c4279ad721d3bbe2625a8a0e7c3d55be1d
6
+ metadata.gz: 0f84e35496c067188e94c7d2c0f070dee0f4077db3c24264ef924c2b20cae5ef6fa1abbba92bd1c24e1c0267392ef3b456a0d8f054f345be1f3366a5d2089436
7
+ data.tar.gz: a2e2bf774eb857ba5d0bbf7d055427e240380dc5467012d5aa0d6e0e03338d8f49a531c026e1901e3c8697ca3c42ad1301cfb9c44186e79e3438465e29b50921
@@ -1,7 +1,9 @@
1
1
  module Semaphore
2
+ module_function
3
+
2
4
  require "optparse"
3
5
 
4
- def self.parse
6
+ def parse
5
7
  options = {}
6
8
 
7
9
  parser = OptionParser.new do |opts|
@@ -0,0 +1,71 @@
1
+ module Semaphore
2
+ require "json"
3
+ require "test_boosters/cli_parser"
4
+ require "test_boosters/logger"
5
+ require "test_boosters/executor"
6
+ require "test_boosters/display_files"
7
+ require "test_boosters/leftover_files"
8
+
9
+ class CucumberBooster
10
+ def initialize(thread_index)
11
+ @thread_index = thread_index
12
+ @report_path = ENV["REPORT_PATH"] || "#{ENV["HOME"]}/cucumber_report.json"
13
+ @spec_path = ENV["SPEC_PATH"] || "features"
14
+ end
15
+
16
+ def run
17
+ begin
18
+ features_to_run = select
19
+
20
+ if features_to_run.empty?
21
+ puts "No feature files in this thread!"
22
+ else
23
+ Semaphore::execute("bundle exec cucumber #{features_to_run.join(" ")}")
24
+ end
25
+ rescue StandardError => e
26
+ if @thread_index == 0
27
+ Semaphore::execute("bundle exec cucumber #{@spec_path}")
28
+ end
29
+ end
30
+ end
31
+
32
+ def select
33
+ with_fallback do
34
+ feature_report = JSON.parse(File.read(@report_path))
35
+ thread_count = feature_report.count
36
+ thread = feature_report[@thread_index]
37
+
38
+ all_features = Dir["#{@spec_path}/**/*.feature"].sort
39
+ all_known_features = feature_report.map { |t| t["files"] }.flatten.sort
40
+
41
+ all_leftover_features = all_features - all_known_features
42
+ thread_leftover_features = LeftoverFiles::select(all_leftover_features, thread_count, @thread_index)
43
+ thread_features = all_features & thread["files"].sort
44
+ features_to_run = thread_features + thread_leftover_features
45
+
46
+ Semaphore::display_files("This thread specs:", thread_features)
47
+ Semaphore::display_files("This thread leftover specs:", thread_leftover_features)
48
+ Semaphore::display_files("All leftover specs:", all_leftover_features)
49
+
50
+ features_to_run
51
+ end
52
+ end
53
+
54
+ def with_fallback
55
+ yield
56
+ rescue StandardError => e
57
+ error = %{
58
+ WARNING: An error detected while parsing the test boosters report file.
59
+ WARNING: All tests will be executed on the first thread.
60
+ }
61
+
62
+ puts error
63
+
64
+ error += %{Exception: #{e.message}}
65
+
66
+ Semaphore::log(error)
67
+
68
+ raise
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,7 @@
1
1
  module Semaphore
2
- def self.display_files(title, files)
2
+ module_function
3
+
4
+ def display_files(title, files)
3
5
  puts "#{title} #{files.count}\n"
4
6
 
5
7
  files.each { |file| puts "- #{file}" }
@@ -1,5 +1,7 @@
1
1
  module Semaphore
2
- def self.execute(command)
2
+ module_function
3
+
4
+ def execute(command)
3
5
  log("Running command: #{command}")
4
6
  system(command)
5
7
  log("Command finished, exit status : #{$?.exitstatus}")
@@ -0,0 +1,29 @@
1
+ module LeftoverFiles
2
+ module_function
3
+
4
+ def self.select(all_leftover_files, thread_count, thread_index)
5
+ all_leftover_files = sort_by_size(all_leftover_files)
6
+
7
+ return [] if all_leftover_files.empty?
8
+
9
+ files = all_leftover_files
10
+ .each_slice(thread_count)
11
+ .reduce{ |acc, slice| acc.map{|a| a}.zip(slice.reverse) }
12
+ .map{ |f| f.kind_of?(Array) ? f.flatten : [f] } [thread_index]
13
+
14
+ if files.nil? then []
15
+ elsif files.kind_of?(Array) then files.compact
16
+ end
17
+ end
18
+
19
+ def self.sort_by_size(files) # descending
20
+ files
21
+ .select { |f| File.file?(f) }
22
+ .map{ |f| [f, File.size(f)] }
23
+ .sort_by{ |a| a[1] }
24
+ .map{ |a| a[0] }
25
+ .reverse
26
+ end
27
+
28
+
29
+ end
@@ -1,5 +1,7 @@
1
1
  module Semaphore
2
- def self.log(message)
2
+ module_function
3
+
4
+ def log(message)
3
5
  error_log_path = ENV["ERROR_LOG_PATH"] || "#{ENV["HOME"]}/test_booster_error.log"
4
6
 
5
7
  File.open(error_log_path, "a") { |f| f.write("#{message}\n") }
@@ -4,11 +4,9 @@ module Semaphore
4
4
  require "test_boosters/logger"
5
5
  require "test_boosters/executor"
6
6
  require "test_boosters/display_files"
7
- require "test_boosters/leftover_specs"
7
+ require "test_boosters/leftover_files"
8
8
 
9
9
  class RspecBooster
10
- Error = -1
11
-
12
10
  def initialize(thread_index)
13
11
  @thread_index = thread_index
14
12
  @report_path = ENV["REPORT_PATH"] || "#{ENV["HOME"]}/rspec_report.json"
@@ -16,16 +14,18 @@ module Semaphore
16
14
  end
17
15
 
18
16
  def run
19
- specs_to_run = select
17
+ begin
18
+ specs_to_run = select
20
19
 
21
- if specs_to_run == Error
20
+ if specs_to_run.empty?
21
+ puts "No spec files in this thread!"
22
+ else
23
+ Semaphore::execute("bundle exec rspec #{specs_to_run.join(" ")}")
24
+ end
25
+ rescue StandardError => e
22
26
  if @thread_index == 0
23
27
  Semaphore::execute("bundle exec rspec #{@spec_path}")
24
28
  end
25
- elsif specs_to_run.empty?
26
- puts "No spec files in this thread!"
27
- else
28
- Semaphore::execute("bundle exec rspec #{specs_to_run.join(" ")}")
29
29
  end
30
30
  end
31
31
 
@@ -39,7 +39,7 @@ module Semaphore
39
39
  all_known_specs = rspec_report.map { |t| t["files"] }.flatten.sort
40
40
 
41
41
  all_leftover_specs = all_specs - all_known_specs
42
- thread_leftover_specs = LeftoverSpecs.select(all_leftover_specs, thread_count, @thread_index)
42
+ thread_leftover_specs = LeftoverFiles::select(all_leftover_specs, thread_count, @thread_index)
43
43
  thread_specs = all_specs & thread["files"].sort
44
44
  specs_to_run = thread_specs + thread_leftover_specs
45
45
 
@@ -66,7 +66,7 @@ module Semaphore
66
66
 
67
67
  Semaphore::log(error)
68
68
 
69
- Error
69
+ raise
70
70
  end
71
71
 
72
72
  end
@@ -1,3 +1,3 @@
1
1
  module TestBoosters
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/test_boosters.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "test_boosters/version"
2
2
  require "test_boosters/rspec_booster"
3
+ require "test_boosters/cucumber_booster"
3
4
 
4
5
  module TestBoosters
5
6
  # Your code goes here...
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test_boosters/cucumber_booster"
4
+
5
+ cli_options = Semaphore::parse
6
+ thread_index = cli_options[:index] - 1
7
+ cucumber_booster = Semaphore::CucumberBooster.new(thread_index)
8
+ cucumber_booster.run
@@ -0,0 +1 @@
1
+ 12345678901234567890
@@ -0,0 +1 @@
1
+ 123
@@ -0,0 +1 @@
1
+ 123456789
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semaphore_test_boosters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MAINTAINER Rendered Text
@@ -70,16 +70,21 @@ files:
70
70
  - bin/setup
71
71
  - lib/test_boosters.rb
72
72
  - lib/test_boosters/cli_parser.rb
73
+ - lib/test_boosters/cucumber_booster.rb
73
74
  - lib/test_boosters/display_files.rb
74
75
  - lib/test_boosters/executor.rb
75
- - lib/test_boosters/leftover_specs.rb
76
+ - lib/test_boosters/leftover_files.rb
76
77
  - lib/test_boosters/logger.rb
77
78
  - lib/test_boosters/rspec_booster.rb
78
79
  - lib/test_boosters/version.rb
80
+ - script/cucumber_booster
79
81
  - script/rspec_booster
80
82
  - test_boosters.gemspec
83
+ - test_data/a.feature
81
84
  - test_data/a_spec.rb
85
+ - test_data/b.feature
82
86
  - test_data/b_spec.rb
87
+ - test_data/c.feature
83
88
  - test_data/c_spec.rb
84
89
  homepage: https://github.com/renderedtext/test-boosters
85
90
  licenses:
@@ -1,26 +0,0 @@
1
- module LeftoverSpecs
2
- def self.select(all_leftover_specs, thread_count, thread_index)
3
- all_leftover_specs = sort_by_size(all_leftover_specs)
4
-
5
- return [] if all_leftover_specs.empty?
6
-
7
- specs = all_leftover_specs
8
- .each_slice(thread_count)
9
- .reduce{|acc, slice| acc.map{|a| a}.zip(slice.reverse)}
10
- .map{|f| if f.kind_of?(Array) then f.flatten else [f] end} [thread_index]
11
-
12
- if specs.nil? then []
13
- elsif specs.kind_of?(Array) then specs.compact
14
- end
15
- end
16
-
17
- def self.sort_by_size(specs) # descending
18
- specs
19
- .map{|f| if File.file?(f) then f else nil end}
20
- .compact
21
- .map{|f| [f, File.size(f)]}
22
- .sort_by{|a| a[1]}.map{|a| a[0]}.reverse
23
- end
24
-
25
-
26
- end