in-parallel 0.1.16 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NGJlY2ZkMDkyMjM3MGE4NGIxNjljNDU1YTE1NGRkYWY2OWE2NjZkZA==
5
- data.tar.gz: !binary |-
6
- ZmQ4NmExZGJmYmZiNDM5NjM1MWQ1OGM5MTMwMGMwMjYzMDdjY2ViOQ==
2
+ SHA256:
3
+ metadata.gz: 2dc8f03c43e170dbb67bef4ababe42609c769a03202ede4fbb6248a88be11fd6
4
+ data.tar.gz: 13f4848ebf63e8615d5442d3ace5e17ba7c771a2f14e7a8ac6bb1a107a8999f6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGFjZTBkNGUzYTEwYWFkMDY0YWVhNGIxNjc2MzhkOWUwNTg5Y2NjNmQxOTAy
10
- ZjAwNTliZWJmZTU4NjU1ODg0OGExNmRkZTljMzk0OWQyZGU2ODFhOWQ3ZTUw
11
- ZWQzNTRkMjY5YzM5MGYyZGViNGY4MjVhMjQwMDExYjE5MTQ3ZWY=
12
- data.tar.gz: !binary |-
13
- OWEyOGQ2MWJiY2RiZTVhNTMxM2VhNDllM2MwNmM2ZTVjNWVhNjljMjcxZDU4
14
- NWIxNTAxNzMyZDM1YWZlYjhhOWQ2Y2I0NzRmNGZmOWJlN2EzOTlhYTA5ZTk2
15
- NDZlZGVhYmYyYzFkOTcwN2E0MWY4NjQ1NTEzOGZmMGE0OGE0MWM=
6
+ metadata.gz: '0920d576695d90a654c77e3d59368783f1b03b8c7cdfd302779b4923ab5fed1f67c8e9dacef05bb39dfedfc13a0c18ec594975bbfcd91b276decd147afe94fd6'
7
+ data.tar.gz: d56bf699d25ab60872463c6883ba774278de655d1996a1e75f661c52e1faf729bd47101e7316ab1dbbb3705a7c58ce412af630bbcb54a2d2c4c8f70c171ffaeb
data/CHANGELOG.md ADDED
@@ -0,0 +1,152 @@
1
+ # Changelog
2
+
3
+ ## [1.0.0](https://github.com/puppetlabs/in-parallel/tree/1.0.0) (2023-03-15)
4
+
5
+ [Full Changelog](https://github.com/puppetlabs/in-parallel/compare/0.1.17...1.0.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - \(RE-15226\) Update codeowners and add standard workflows [\#20](https://github.com/puppetlabs/in-parallel/pull/20) ([yachub](https://github.com/yachub))
10
+ - \(maint\) update exists? -\> exist? for ruby 3.2 compatibility [\#19](https://github.com/puppetlabs/in-parallel/pull/19) ([tvpartytonight](https://github.com/tvpartytonight))
11
+
12
+ ## [0.1.17](https://github.com/puppetlabs/in-parallel/tree/0.1.17) (2017-02-07)
13
+
14
+ [Full Changelog](https://github.com/puppetlabs/in-parallel/compare/0.1.16...0.1.17)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - \(maint\) Properly handle non-parallel enumerables [\#17](https://github.com/puppetlabs/in-parallel/pull/17) ([nicklewis](https://github.com/nicklewis))
19
+
20
+ ## [0.1.16](https://github.com/puppetlabs/in-parallel/tree/0.1.16) (2017-02-06)
21
+
22
+ [Full Changelog](https://github.com/puppetlabs/in-parallel/compare/0.1.15...0.1.16)
23
+
24
+ ## [0.1.15](https://github.com/puppetlabs/in-parallel/tree/0.1.15) (2017-02-03)
25
+
26
+ [Full Changelog](https://github.com/puppetlabs/in-parallel/compare/0.1.14...0.1.15)
27
+
28
+ **Merged pull requests:**
29
+
30
+ - \(maint\) Avoid deadlock with large results [\#16](https://github.com/puppetlabs/in-parallel/pull/16) ([nicklewis](https://github.com/nicklewis))
31
+ - \(maint\) Revert name change of in\_parallel.rb [\#15](https://github.com/puppetlabs/in-parallel/pull/15) ([samwoods1](https://github.com/samwoods1))
32
+
33
+ ## [0.1.14](https://github.com/puppetlabs/in-parallel/tree/0.1.14) (2016-08-08)
34
+
35
+ [Full Changelog](https://github.com/puppetlabs/in-parallel/compare/0.1.13...0.1.14)
36
+
37
+ **Merged pull requests:**
38
+
39
+ - \(maint\) Consistent naming of in-parallel [\#14](https://github.com/puppetlabs/in-parallel/pull/14) ([samwoods1](https://github.com/samwoods1))
40
+
41
+ # experimental_in-parallel_bump_and_tag_master - History
42
+ ## Tags
43
+ * [LATEST - 6 Feb, 2017 (8e97ff25)](#LATEST)
44
+ * [0.1.16 - 6 Feb, 2017 (0d5030c3)](#0.1.16)
45
+ * [0.1.15 - 3 Feb, 2017 (ff16929c)](#0.1.15)
46
+ * [0.1.14 - 8 Aug, 2016 (ce331dbd)](#0.1.14)
47
+ * [0.1.13 - 8 Aug, 2016 (26d19934)](#0.1.13)
48
+
49
+ ## Details
50
+ ### <a name = "LATEST">LATEST - 6 Feb, 2017 (8e97ff25)
51
+
52
+ * (GEM) update in-parallel version to 0.1.17 (8e97ff25)
53
+
54
+ * Merge pull request #17 from nicklewis/handle-non-parallel-enumerables (dca0b0a5)
55
+
56
+
57
+ ```
58
+ Merge pull request #17 from nicklewis/handle-non-parallel-enumerables
59
+
60
+ (maint) Properly handle non-parallel enumerables
61
+ ```
62
+ * (maint) Properly handle non-parallel enumerables (b041b864)
63
+
64
+
65
+ ```
66
+ (maint) Properly handle non-parallel enumerables
67
+
68
+ For Enumerables containing 0 or 1 items, the #each_in_parallel method
69
+ was improperly calling the block without an argument, then calling it
70
+ again properly but not returning the result of the block.
71
+
72
+ The #each method returns the Enumerable that was it was called on,
73
+ rather than the value of the block. This needs to be #map instead, to
74
+ actually return an array of the one or zero values. The tests weren't
75
+ catching this because they were effectively passing `identity` as the
76
+ block, nullifying the distinction between #each and #map.
77
+ ```
78
+ ### <a name = "0.1.16">0.1.16 - 6 Feb, 2017 (0d5030c3)
79
+
80
+ * (HISTORY) update in-parallel history for gem release 0.1.16 (0d5030c3)
81
+
82
+ * (GEM) update in-parallel version to 0.1.16 (27b497ea)
83
+
84
+ ### <a name = "0.1.15">0.1.15 - 3 Feb, 2017 (ff16929c)
85
+
86
+ * (HISTORY) update in-parallel history for gem release 0.1.15 (ff16929c)
87
+
88
+ * (GEM) update in-parallel version to 0.1.15 (206a62fe)
89
+
90
+ * Merge pull request #16 from nicklewis/support-large-results (4d644d88)
91
+
92
+
93
+ ```
94
+ Merge pull request #16 from nicklewis/support-large-results
95
+
96
+ (maint) Avoid deadlock with large results
97
+ ```
98
+ * (maint) Avoid deadlock with large results (a5a9c174)
99
+
100
+
101
+ ```
102
+ (maint) Avoid deadlock with large results
103
+
104
+ Previously, if the result of a process was larger than the IO buffer
105
+ size (commonly 64k), execution would deadlock until the timeout.
106
+
107
+ In this scenario, the writer would fill the buffer and block until the
108
+ reader had cleared the buffer by reading. However, the reader will only
109
+ try to read once (to get the whole result) and will only attempt to read
110
+ after the child process has exited. This causes a deadlock, as the child
111
+ can't exit because it can't finish writing, but the the reader won't
112
+ read because the child hasn't exited.
113
+
114
+ This commit fixes the watcher loop to instead IO.select() from the
115
+ available result readers and read a partial result into a buffer whenever it's
116
+ available. This ensures that the writer will never remain blocked by a
117
+ full buffer. The reader now uses IO#eof? to determine whether the child
118
+ process has exited, at which point it will process the whole result as
119
+ before.
120
+ ```
121
+ * Merge pull request #15 from samwoods1/add_jjb_pipelines (72d32635)
122
+
123
+
124
+ ```
125
+ Merge pull request #15 from samwoods1/add_jjb_pipelines
126
+
127
+ (maint) Revert name change of in_parallel.rb
128
+ ```
129
+ * (maint) Revert name change of in_parallel.rb (327c8fd5)
130
+
131
+ ### <a name = "0.1.14">0.1.14 - 8 Aug, 2016 (ce331dbd)
132
+
133
+ * (HISTORY) update in-parallel history for gem release 0.1.14 (ce331dbd)
134
+
135
+ * (GEM) update in-parallel version to 0.1.14 (d026c624)
136
+
137
+ * Merge pull request #14 from samwoods1/add_jjb_pipelines (269bc350)
138
+
139
+
140
+ ```
141
+ Merge pull request #14 from samwoods1/add_jjb_pipelines
142
+
143
+ (maint) Consistent naming of in-parallel
144
+ ```
145
+ * (maint) Consistent naming of in-parallel (6fbb442d)
146
+
147
+ ### <a name = "0.1.13">0.1.13 - 8 Aug, 2016 (26d19934)
148
+
149
+ * Initial release.
150
+
151
+
152
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/CODEOWNERS ADDED
@@ -0,0 +1,8 @@
1
+ # This will cause RE to be assigned review of any opened PRs against
2
+ # the branches containing this file.
3
+ # See https://help.github.com/en/articles/about-code-owners for info on how to
4
+ # take ownership of parts of the code base that should be reviewed by another
5
+ # team.
6
+
7
+ # RE will be the default owners for everything in the repo.
8
+ * @puppetlabs/release-engineering
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # in the Rakefile, so we require it in all groups
4
- gem 'rspec' ,'~> 3.1.0'
4
+ gem 'rspec' ,'~> 3.1'
5
5
 
6
6
  group :development do
7
7
  gem 'simplecov'
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ in-parallel (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (7.0.4.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ concurrent-ruby (1.2.2)
15
+ diff-lcs (1.5.0)
16
+ docile (1.4.0)
17
+ i18n (1.12.0)
18
+ concurrent-ruby (~> 1.0)
19
+ iniparser (1.0.1)
20
+ kramdown (2.4.0)
21
+ rexml
22
+ logutils (0.6.1)
23
+ markdown (0.4.0)
24
+ kramdown (>= 0.13.7)
25
+ props (>= 0.2.0)
26
+ textutils (>= 0.2.0)
27
+ minitest (5.18.0)
28
+ props (1.2.0)
29
+ iniparser (>= 0.1.0)
30
+ rake (13.0.6)
31
+ rexml (3.2.5)
32
+ rspec (3.12.0)
33
+ rspec-core (~> 3.12.0)
34
+ rspec-expectations (~> 3.12.0)
35
+ rspec-mocks (~> 3.12.0)
36
+ rspec-core (3.12.1)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-expectations (3.12.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-mocks (3.12.4)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.0)
45
+ rubyzip (2.3.2)
46
+ simplecov (0.22.0)
47
+ docile (~> 1.1)
48
+ simplecov-html (~> 0.11)
49
+ simplecov_json_formatter (~> 0.1)
50
+ simplecov-html (0.12.3)
51
+ simplecov_json_formatter (0.1.4)
52
+ textutils (1.4.0)
53
+ activesupport
54
+ logutils (>= 0.6.1)
55
+ props (>= 1.1.2)
56
+ rubyzip (>= 1.0.0)
57
+ tzinfo (2.0.6)
58
+ concurrent-ruby (~> 1.0)
59
+ webrick (1.7.0)
60
+ yard (0.9.28)
61
+ webrick (~> 1.7.0)
62
+
63
+ PLATFORMS
64
+ aarch64-linux
65
+ x86_64-linux
66
+
67
+ DEPENDENCIES
68
+ in-parallel!
69
+ markdown (~> 0)
70
+ rake (>= 0.9.0)
71
+ rspec (~> 3.1)
72
+ simplecov
73
+ yard (~> 0)
74
+
75
+ BUNDLED WITH
76
+ 2.4.8
data/HISTORY.md CHANGED
@@ -1,12 +1,43 @@
1
1
  # experimental_in-parallel_bump_and_tag_master - History
2
2
  ## Tags
3
- * [LATEST - 6 Feb, 2017 (27b497ea)](#LATEST)
3
+ * [LATEST - 6 Feb, 2017 (8e97ff25)](#LATEST)
4
+ * [0.1.16 - 6 Feb, 2017 (0d5030c3)](#0.1.16)
4
5
  * [0.1.15 - 3 Feb, 2017 (ff16929c)](#0.1.15)
5
6
  * [0.1.14 - 8 Aug, 2016 (ce331dbd)](#0.1.14)
6
7
  * [0.1.13 - 8 Aug, 2016 (26d19934)](#0.1.13)
7
8
 
8
9
  ## Details
9
- ### <a name = "LATEST">LATEST - 6 Feb, 2017 (27b497ea)
10
+ ### <a name = "LATEST">LATEST - 6 Feb, 2017 (8e97ff25)
11
+
12
+ * (GEM) update in-parallel version to 0.1.17 (8e97ff25)
13
+
14
+ * Merge pull request #17 from nicklewis/handle-non-parallel-enumerables (dca0b0a5)
15
+
16
+
17
+ ```
18
+ Merge pull request #17 from nicklewis/handle-non-parallel-enumerables
19
+
20
+ (maint) Properly handle non-parallel enumerables
21
+ ```
22
+ * (maint) Properly handle non-parallel enumerables (b041b864)
23
+
24
+
25
+ ```
26
+ (maint) Properly handle non-parallel enumerables
27
+
28
+ For Enumerables containing 0 or 1 items, the #each_in_parallel method
29
+ was improperly calling the block without an argument, then calling it
30
+ again properly but not returning the result of the block.
31
+
32
+ The #each method returns the Enumerable that was it was called on,
33
+ rather than the value of the block. This needs to be #map instead, to
34
+ actually return an array of the one or zero values. The tests weren't
35
+ catching this because they were effectively passing `identity` as the
36
+ block, nullifying the distinction between #each and #map.
37
+ ```
38
+ ### <a name = "0.1.16">0.1.16 - 6 Feb, 2017 (0d5030c3)
39
+
40
+ * (HISTORY) update in-parallel history for gem release 0.1.16 (0d5030c3)
10
41
 
11
42
  * (GEM) update in-parallel version to 0.1.16 (27b497ea)
12
43
 
data/README.md CHANGED
@@ -1,15 +1,31 @@
1
+ # in-parallel
2
+
3
+ - [in-parallel](#in-parallel)
4
+ - [Use Cases](#use-cases)
5
+ - [Install](#install)
6
+ - [Usage](#usage)
7
+ - [Methods](#methods)
8
+ - [run\_in\_parallel(timeout=nil, kill\_all\_on\_error = false, \&block)](#run_in_paralleltimeoutnil-kill_all_on_error--false-block)
9
+ - [Enumerable.each\_in\_parallel(identifier=nil, timeout=(InParallel::InParallelExecutor.timeout), kill\_all\_on\_error = false, \&block)](#enumerableeach_in_parallelidentifiernil-timeoutinparallelinparallelexecutortimeout-kill_all_on_error--false-block)
10
+ - [run\_in\_background(ignore\_results = true, \&block)](#run_in_backgroundignore_results--true-block)
11
+ - [wait\_for\_processes(timeout=nil, kill\_all\_on\_error = false)](#wait_for_processestimeoutnil-kill_all_on_error--false)
12
+ - [Global Options](#global-options)
13
+ - [Releasing](#releasing)
1
14
 
2
15
  A lightweight Ruby library with very simple syntax, making use of Process.fork to execute code in parallel.
3
16
 
4
- # Use Cases
17
+ ## Use Cases
18
+
5
19
  Many other Ruby libraries that simplify parallel execution support one primary use case - crunching through a large queue of small, similar tasks as quickly and efficiently as possible. This library primarily supports the use case of executing a few larger and unrelated tasks in parallel, automatically managing the stdout and passing return values back to the main process. This library was created to be used by Puppet's Beaker test framework to enable parallel execution of some of the framework's tasks, and allow users to execute code in parallel within their tests.
6
20
 
7
21
  If you are looking for something that excels at executing a large queue of tasks in parallel as efficiently as possible, you should take a look at the [parallel](https://github.com/grosser/parallel) project.
8
22
 
9
- # Install
23
+ ## Install
24
+
10
25
  ```gem install in-parallel```
11
26
 
12
- # Usage
27
+ ## Usage
28
+
13
29
  ```include InParallel``` to use as a mix-in
14
30
 
15
31
  The methods below allow you to fork processes to execute multiple methods or blocks within an enumerable in parallel. They all have this common behavior:
@@ -24,7 +40,9 @@ The methods below allow you to fork processes to execute multiple methods or blo
24
40
  1. Will timeout (stop execution and raise an exception) based on a global timeout value, or timeout parameter.
25
41
 
26
42
  ## Methods
43
+
27
44
  ### run_in_parallel(timeout=nil, kill_all_on_error = false, &block)
45
+
28
46
  1. Each method in a block will be executed in parallel (unless the method is defined in Kernel or BaseObject).
29
47
  1. Any methods further down the stack won't be affected, only the ones directly within the block.
30
48
  1. Waits for each process in realtime and logs immediately upon completion of each process
@@ -53,8 +71,10 @@ The methods below allow you to fork processes to execute multiple methods or blo
53
71
 
54
72
  puts "#{@result_1}, #{@result_2[:foo]}"
55
73
  ```
74
+
56
75
  stdout:
57
- ```
76
+
77
+ ```shell
58
78
  Forked process for 'method_with_param' - PID = '49398'
59
79
  Forked process for 'method_without_param' - PID = '49399'
60
80
 
@@ -67,7 +87,9 @@ hello world
67
87
  ------ Completed output for method_without_param - 49399
68
88
  hello world, bar
69
89
  ```
90
+
70
91
  ### Enumerable.each_in_parallel(identifier=nil, timeout=(InParallel::InParallelExecutor.timeout), kill_all_on_error = false, &block)
92
+
71
93
  1. This is very similar to other solutions, except that it directly extends the Enumerable class with an each_in_parallel method, giving you the ability to pretty simply spawn a process for any item in an array or map.
72
94
  1. Identifies the block location (or caller location if the block does not have a source_location) in the console log to make it clear which block is being executed
73
95
  1. Identifier param is only for logging, otherwise it will use the block source location.
@@ -77,6 +99,7 @@ hello world, bar
77
99
  ```
78
100
 
79
101
  ### run_in_background(ignore_results = true, &block)
102
+
80
103
  1. This does basically the same thing as run_in_parallel, except it does not wait for execution of all processes to complete, it returns immediately.
81
104
  1. You can optionally ignore results completely (default) or delay evaluating the results until later
82
105
  1. You can run multiple blocks in the background and then at some later point evaluate all of the results
@@ -94,11 +117,12 @@ hello world, bar
94
117
  run_in_background { create_file_with_delay(TMP_FILE) }
95
118
 
96
119
  # Should not exist immediately upon block completion
97
- puts(File.exists?(TMP_FILE)) # false
120
+ puts(File.exist?(TMP_FILE)) # false
98
121
  sleep(3)
99
122
  # Should exist once the delay from create_file_with_delay is done
100
- puts(File.exists?(TMP_FILE)) # true
123
+ puts(File.exist?(TMP_FILE)) # true
101
124
  ```
125
+
102
126
  ```ruby
103
127
  # Example 2 - delay results
104
128
  run_in_background(false) { @result = create_file_with_delay(TMP_FILE) }
@@ -118,13 +142,16 @@ hello world, bar
118
142
  ```
119
143
 
120
144
  ### wait_for_processes(timeout=nil, kill_all_on_error = false)
145
+
121
146
  1. Used only after run_in_background with ignore_results=false
122
147
  1. Optional args for timeout and kill_all_on_error
123
148
  1. See run_in_background for examples
124
149
 
125
150
  ## Global Options
151
+
126
152
  You can get or set the following values to set global defaults. These defaults can also be specified per execution by supplying the values as parameters to the parallel methods.
127
- ```
153
+
154
+ ```ruby
128
155
  # How many seconds to wait between logging a 'Waiting for child processes.' message. Defaults to 30 seconds
129
156
  parallel_signal_interval
130
157
 
@@ -137,3 +164,11 @@ You can get or set the following values to set global defaults. These defaults
137
164
  @logger.log_level
138
165
  ```
139
166
 
167
+ ## Releasing
168
+
169
+ Follow these steps to publish a new GitHub release, and build and push the gem to <https://rubygems.org>.
170
+
171
+ 1. Bump the "VERSION" in lib/in-parallel/version.rb appropriately based on changes in CHANGELOG.md since the last release.
172
+ 2. Run `./release-prep` to update `Gemfile.lock` and `CHANGELOG.md`.
173
+ 3. Commit and push changes to a new branch, then open a pull request against main and be sure to add the "maintenance" label.
174
+ 4. After the pull request is approved and merged, then navigate to Actions --> Release Gem --> run workflow --> Branch: main --> Run workflow.
@@ -1,3 +1,3 @@
1
1
  module InParallel
2
- VERSION = '0.1.16'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/in_parallel.rb CHANGED
@@ -152,7 +152,7 @@ module InParallel
152
152
  end
153
153
  results_map[process_info[:index]] = { process_info[:tmp_result] => marshalled_result }
154
154
  ensure
155
- File.delete(process_info[:std_out]) if File.exists?(process_info[:std_out])
155
+ File.delete(process_info[:std_out]) if File.exist?(process_info[:std_out])
156
156
  # close the read end pipe
157
157
  process_info[:result].close unless process_info[:result].closed?
158
158
  @@process_infos.delete(process_info)
@@ -185,7 +185,7 @@ module InParallel
185
185
  ret_val = nil
186
186
  # Communicate the return value of the method or block
187
187
  read_result, write_result = IO.pipe
188
- Dir.mkdir('tmp') unless Dir.exists? 'tmp'
188
+ Dir.mkdir('tmp') unless Dir.exist? 'tmp'
189
189
  pid = fork do
190
190
  stdout_file = File.new("tmp/pp_#{Process.pid}", 'w')
191
191
  exit_status = 0
@@ -16,9 +16,9 @@ module Enumerable
16
16
  end
17
17
  # return the array of values, no need to look up from the map.
18
18
  return InParallel::InParallelExecutor.wait_for_processes(nil, block.binding, timeout, kill_all_on_error)
19
+ else
20
+ # If fork is not supported
21
+ map(&block)
19
22
  end
20
- # If fork is not supported
21
- block.call
22
- each(&block)
23
23
  end
24
24
  end
@@ -75,7 +75,7 @@ end
75
75
  #Tests
76
76
  describe '.run_in_parallel' do
77
77
  before do
78
- File.delete(TMP_FILE) if File.exists?(TMP_FILE)
78
+ File.delete(TMP_FILE) if File.exist?(TMP_FILE)
79
79
  end
80
80
 
81
81
  it 'should run methods in another process' do
@@ -169,7 +169,7 @@ end
169
169
 
170
170
  describe '.run_in_background' do
171
171
  before do
172
- File.delete(TMP_FILE) if File.exists?(TMP_FILE)
172
+ File.delete(TMP_FILE) if File.exist?(TMP_FILE)
173
173
  end
174
174
 
175
175
  it 'should run in the background' do
@@ -177,11 +177,11 @@ describe '.run_in_background' do
177
177
 
178
178
  start = Time.now
179
179
  # Should not exist immediately upon block completion
180
- expect(File.exists? TMP_FILE).to eq false
180
+ expect(File.exist? TMP_FILE).to eq false
181
181
  # Give this some time to complete since it takes longer on the vmpooler vms
182
182
  file_exists = false
183
183
  while Time.now < start + 10 do
184
- if File.exists? TMP_FILE
184
+ if File.exist? TMP_FILE
185
185
  file_exists = true
186
186
  break
187
187
  end
@@ -228,23 +228,36 @@ describe '.each_in_parallel' do
228
228
 
229
229
  it 'should return correct values' do
230
230
  start_time = Time.now
231
- items = ['foo', 'bar', 'baz', 'blah', 'foobar'].each_in_parallel do |item|
231
+ items = [1,2,3,4,5].each_in_parallel do |item|
232
232
  sleep(Random.rand(1.0))
233
- item
233
+ item * 2
234
234
  end
235
235
  # return values should be an array of the returned items in the last line of the block, in correct order
236
- expect(['foo', 'bar', 'baz', 'blah', 'foobar']).to eq(items)
236
+ expect(items).to eq([2,4,6,8,10])
237
237
  # time should be less than combined delay in the 3 block calls
238
238
  expect(expect(Time.now - start_time).to be < 5)
239
239
  end
240
240
 
241
241
  it 'should run each iteration of a map in parallel' do
242
- items = ['foo', 'bar', 'baz'].map.each_in_parallel do |item|
242
+ items = [1,2,3].map.each_in_parallel do |item|
243
243
  puts item
244
- item
244
+ item * 2
245
245
  end
246
246
  # return values should be an array of the returned items in the last line of the block, in correct order
247
- expect(items).to eq(['foo', 'bar', 'baz'])
247
+ expect(items).to eq([2,4,6])
248
+ end
249
+
250
+ it 'should return an empty array and do nothing with an empty enumerator' do
251
+ result = [].each_in_parallel do |item|
252
+ raise "Incorrectly called the block with an empty enumerator"
253
+ end
254
+ expect(result).to eq []
255
+ end
256
+
257
+ it 'should return the result of the block with only 1 item in the enumerator' do
258
+ expect([1].each_in_parallel do |item|
259
+ item * 2
260
+ end).to eq([2])
248
261
  end
249
262
 
250
263
  it 'should not run in parallel if there is only 1 item in the enumerator' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in-parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - samwoods1
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Many other Ruby libraries that simplify parallel execution support one
14
14
  primary use case - crunching through a large queue of small, similar tasks as quickly
@@ -24,11 +24,13 @@ executables: []
24
24
  extensions: []
25
25
  extra_rdoc_files: []
26
26
  files:
27
+ - CHANGELOG.md
28
+ - CODEOWNERS
27
29
  - CONTRIBUTING.md
28
30
  - Gemfile
31
+ - Gemfile.lock
29
32
  - HISTORY.md
30
33
  - LICENSE
31
- - MAINTAINERS.md
32
34
  - README.md
33
35
  - Rakefile
34
36
  - lib/in-parallel/version.rb
@@ -46,17 +48,16 @@ require_paths:
46
48
  - lib
47
49
  required_ruby_version: !ruby/object:Gem::Requirement
48
50
  requirements:
49
- - - ! '>='
51
+ - - ">="
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  required_rubygems_version: !ruby/object:Gem::Requirement
53
55
  requirements:
54
- - - ! '>='
56
+ - - ">="
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 2.4.6
60
+ rubygems_version: 3.4.6
60
61
  signing_key:
61
62
  specification_version: 4
62
63
  summary: A lightweight library to execute a handful of tasks in parallel with simple
data/MAINTAINERS.md DELETED
@@ -1,9 +0,0 @@
1
- # Reviewers/Maintainers For in-parallel
2
-
3
- in-parallel is maintained by Puppet's Quality Assurance (QA) Team. These people
4
- will be reviewing & merging PRs to the project.
5
-
6
- | Name | Github | Email |
7
- |:--------------:|:---------------------------------------------------:|:---------------------------:|
8
- | Sam Woods | [samwoods1](https://github.com/samwoods1) | <sam.woods@puppet.com> |
9
- | Zach Reichert | [zreichert](https://github.com/zreichert) | <zach.reichert@puppet.com> |