rspec-parallel 2.14.8.1 → 2.14.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +1,49 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Parallel
|
3
|
-
# ExampleGroupThreadRunner is a class used to execute [ExampleGroup]
|
4
|
-
# classes in parallel as part of rspec-core. When running in parallel
|
5
|
-
# the order of example groups will not be honoured.
|
6
|
-
# This class is used to ensure that we have a way of keeping track of
|
7
|
-
# the number of threads being created and preventing utilization of
|
8
|
-
# more than the specified number
|
9
|
-
# Additionally, this class will contain a mutex used to prevent access
|
10
|
-
# to shared variables within sub-threads
|
11
|
-
class ExampleGroupThreadRunner
|
12
|
-
attr_accessor :thread_array, :max_threads, :mutex, :used_threads
|
13
|
-
|
14
|
-
# Creates a new instance of ExampleGroupThreadRunner.
|
15
|
-
# @param max_threads [Integer] the maximum limit of threads that can be used
|
16
|
-
# @param mutex [Mutex] a semaphore used to prevent access to shared variables in
|
17
|
-
# sub-threads such as those used by [ExampleThreadRunner]
|
18
|
-
# @param used_threads [Integer] the current number of threads being used
|
19
|
-
def initialize(max_threads = 1, mutex = Mutex.new, used_threads = 0)
|
20
|
-
@max_threads = max_threads
|
21
|
-
@mutex = mutex
|
22
|
-
@used_threads = used_threads
|
23
|
-
@thread_array = []
|
24
|
-
end
|
25
|
-
|
26
|
-
# Method will run an [ExampleGroup] inside a [Thread] to prevent blocking
|
27
|
-
# execution. The new [Thread] is added to an array for tracking and
|
28
|
-
# will automatically remove itself when done
|
29
|
-
# @param example_group [ExampleGroup] the group to be run inside a [Thread]
|
30
|
-
# @param reporter [Reporter] the passed in reporting class used for
|
31
|
-
# tracking
|
32
|
-
def run(example_group, reporter)
|
33
|
-
@thread_array.push Thread.start {
|
34
|
-
example_group.run_parallel(reporter, @max_threads, @mutex, @used_threads)
|
35
|
-
@thread_array.delete Thread.current
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
# Method will wait for all threads to complete. On completion threads
|
40
|
-
# remove themselves from the @thread_array so an empty array means they
|
41
|
-
# completed
|
42
|
-
def wait_for_completion
|
43
|
-
@thread_array.each do |t|
|
44
|
-
t.join
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Parallel
|
3
|
+
# ExampleGroupThreadRunner is a class used to execute [ExampleGroup]
|
4
|
+
# classes in parallel as part of rspec-core. When running in parallel
|
5
|
+
# the order of example groups will not be honoured.
|
6
|
+
# This class is used to ensure that we have a way of keeping track of
|
7
|
+
# the number of threads being created and preventing utilization of
|
8
|
+
# more than the specified number
|
9
|
+
# Additionally, this class will contain a mutex used to prevent access
|
10
|
+
# to shared variables within sub-threads
|
11
|
+
class ExampleGroupThreadRunner
|
12
|
+
attr_accessor :thread_array, :max_threads, :mutex, :used_threads
|
13
|
+
|
14
|
+
# Creates a new instance of ExampleGroupThreadRunner.
|
15
|
+
# @param max_threads [Integer] the maximum limit of threads that can be used
|
16
|
+
# @param mutex [Mutex] a semaphore used to prevent access to shared variables in
|
17
|
+
# sub-threads such as those used by [ExampleThreadRunner]
|
18
|
+
# @param used_threads [Integer] the current number of threads being used
|
19
|
+
def initialize(max_threads = 1, mutex = Mutex.new, used_threads = 0)
|
20
|
+
@max_threads = max_threads
|
21
|
+
@mutex = mutex
|
22
|
+
@used_threads = used_threads
|
23
|
+
@thread_array = []
|
24
|
+
end
|
25
|
+
|
26
|
+
# Method will run an [ExampleGroup] inside a [Thread] to prevent blocking
|
27
|
+
# execution. The new [Thread] is added to an array for tracking and
|
28
|
+
# will automatically remove itself when done
|
29
|
+
# @param example_group [ExampleGroup] the group to be run inside a [Thread]
|
30
|
+
# @param reporter [Reporter] the passed in reporting class used for
|
31
|
+
# tracking
|
32
|
+
def run(example_group, reporter)
|
33
|
+
@thread_array.push Thread.start {
|
34
|
+
example_group.run_parallel(reporter, @max_threads, @mutex, @used_threads)
|
35
|
+
@thread_array.delete Thread.current
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Method will wait for all threads to complete. On completion threads
|
40
|
+
# remove themselves from the @thread_array so an empty array means they
|
41
|
+
# completed
|
42
|
+
def wait_for_completion
|
43
|
+
@thread_array.each do |t|
|
44
|
+
t.join
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Parallel
|
3
|
-
# ExampleThreadRunner is a class used to execute [Example] classes in
|
4
|
-
# parallel as part of rspec-core. When running in parallel the order
|
5
|
-
# of examples will not be honoured.
|
6
|
-
# This class is used to ensure that we have a way of keeping track of
|
7
|
-
# the number of threads being created and preventing utilization of
|
8
|
-
# more than the specified number
|
9
|
-
class ExampleThreadRunner
|
10
|
-
attr_accessor :num_threads, :thread_array, :used_threads
|
11
|
-
|
12
|
-
# Creates a new instance of ExampleThreadRunner.
|
13
|
-
# @param num_threads [Integer] the maximum limit of threads that can be used
|
14
|
-
# @param used_threads [Integer] the current number of threads being used
|
15
|
-
def initialize(num_threads, used_threads)
|
16
|
-
@num_threads = num_threads
|
17
|
-
@thread_array = []
|
18
|
-
@used_threads = used_threads
|
19
|
-
end
|
20
|
-
|
21
|
-
# Method will check global utilization of threads and if that number is
|
22
|
-
# at or over the allocated maximum it will wait until a thread is available
|
23
|
-
def wait_for_available_thread
|
24
|
-
while @used_threads.to_i >= @num_threads.to_i
|
25
|
-
sleep 0.1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Method will run the specified example within an available thread or
|
30
|
-
# will wait for a thread to become available if none currently are
|
31
|
-
# @param example [Example] the example to be executed in a [Thread]
|
32
|
-
# @param instance the instance of an ExampleGroup subclass
|
33
|
-
# @param reporter [Reporter] the passed in reporting class used for
|
34
|
-
# tracking
|
35
|
-
def run(example, instance, reporter)
|
36
|
-
wait_for_available_thread
|
37
|
-
@thread_array.push Thread.start {
|
38
|
-
example.run(instance, reporter)
|
39
|
-
@thread_array.delete Thread.current # remove from local scope
|
40
|
-
@used_threads -= 1
|
41
|
-
}
|
42
|
-
@used_threads += 1
|
43
|
-
end
|
44
|
-
|
45
|
-
# Method will wait for all threads to complete. On completion threads
|
46
|
-
# remove themselves from the @thread_array so an empty array means they
|
47
|
-
# completed
|
48
|
-
def wait_for_completion
|
49
|
-
@thread_array.each do |t|
|
50
|
-
t.join
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Parallel
|
3
|
+
# ExampleThreadRunner is a class used to execute [Example] classes in
|
4
|
+
# parallel as part of rspec-core. When running in parallel the order
|
5
|
+
# of examples will not be honoured.
|
6
|
+
# This class is used to ensure that we have a way of keeping track of
|
7
|
+
# the number of threads being created and preventing utilization of
|
8
|
+
# more than the specified number
|
9
|
+
class ExampleThreadRunner
|
10
|
+
attr_accessor :num_threads, :thread_array, :used_threads
|
11
|
+
|
12
|
+
# Creates a new instance of ExampleThreadRunner.
|
13
|
+
# @param num_threads [Integer] the maximum limit of threads that can be used
|
14
|
+
# @param used_threads [Integer] the current number of threads being used
|
15
|
+
def initialize(num_threads, used_threads)
|
16
|
+
@num_threads = num_threads
|
17
|
+
@thread_array = []
|
18
|
+
@used_threads = used_threads
|
19
|
+
end
|
20
|
+
|
21
|
+
# Method will check global utilization of threads and if that number is
|
22
|
+
# at or over the allocated maximum it will wait until a thread is available
|
23
|
+
def wait_for_available_thread
|
24
|
+
while @used_threads.to_i >= @num_threads.to_i
|
25
|
+
sleep 0.1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Method will run the specified example within an available thread or
|
30
|
+
# will wait for a thread to become available if none currently are
|
31
|
+
# @param example [Example] the example to be executed in a [Thread]
|
32
|
+
# @param instance the instance of an ExampleGroup subclass
|
33
|
+
# @param reporter [Reporter] the passed in reporting class used for
|
34
|
+
# tracking
|
35
|
+
def run(example, instance, reporter)
|
36
|
+
wait_for_available_thread
|
37
|
+
@thread_array.push Thread.start {
|
38
|
+
example.run(instance, reporter)
|
39
|
+
@thread_array.delete Thread.current # remove from local scope
|
40
|
+
@used_threads -= 1
|
41
|
+
}
|
42
|
+
@used_threads += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
# Method will wait for all threads to complete. On completion threads
|
46
|
+
# remove themselves from the @thread_array so an empty array means they
|
47
|
+
# completed
|
48
|
+
def wait_for_completion
|
49
|
+
@thread_array.each do |t|
|
50
|
+
t.join
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -23,21 +23,21 @@ module RSpec
|
|
23
23
|
options.parse_options
|
24
24
|
|
25
25
|
parallel = (options.options[:thread_maximum].nil?) ? false : true
|
26
|
+
drb = options.options[:drb]
|
26
27
|
|
27
|
-
if
|
28
|
+
if drb
|
28
29
|
require 'rspec/core/drb_command_line'
|
29
30
|
begin
|
30
31
|
DRbCommandLine.new(options).run(err, out)
|
31
32
|
rescue DRb::DRbConnError
|
32
33
|
err.puts "No DRb server is running. Running in local process instead ..."
|
33
|
-
|
34
|
-
CommandLine.new(options).run_parallel(err, out)
|
35
|
-
else
|
36
|
-
CommandLine.new(options).run(err, out)
|
37
|
-
end
|
34
|
+
drb = false
|
38
35
|
end
|
39
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
unless drb
|
40
39
|
if parallel
|
40
|
+
require 'thread'
|
41
41
|
CommandLine.new(options).run_parallel(err, out)
|
42
42
|
else
|
43
43
|
CommandLine.new(options).run(err, out)
|