chef-utils 16.10.17 → 17.10.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/Rakefile +15 -15
  4. data/chef-utils.gemspec +50 -46
  5. data/lib/chef-utils/dist.rb +151 -98
  6. data/lib/chef-utils/dsl/architecture.rb +150 -150
  7. data/lib/chef-utils/dsl/cloud.rb +155 -144
  8. data/lib/chef-utils/dsl/default_paths.rb +60 -60
  9. data/lib/chef-utils/dsl/introspection.rb +134 -123
  10. data/lib/chef-utils/dsl/os.rb +58 -58
  11. data/lib/chef-utils/dsl/path_sanity.rb +39 -39
  12. data/lib/chef-utils/dsl/platform.rb +387 -372
  13. data/lib/chef-utils/dsl/platform_family.rb +355 -344
  14. data/lib/chef-utils/dsl/platform_version.rb +41 -41
  15. data/lib/chef-utils/dsl/service.rb +112 -112
  16. data/lib/chef-utils/dsl/train_helpers.rb +87 -87
  17. data/lib/chef-utils/dsl/virtualization.rb +272 -250
  18. data/lib/chef-utils/dsl/which.rb +123 -123
  19. data/lib/chef-utils/dsl/windows.rb +86 -86
  20. data/lib/chef-utils/internal.rb +114 -114
  21. data/lib/chef-utils/mash.rb +263 -240
  22. data/lib/chef-utils/parallel_map.rb +131 -0
  23. data/lib/chef-utils/version.rb +20 -20
  24. data/lib/chef-utils/version_string.rb +160 -160
  25. data/lib/chef-utils.rb +53 -53
  26. data/spec/spec_helper.rb +100 -100
  27. data/spec/unit/dsl/architecture_spec.rb +151 -151
  28. data/spec/unit/dsl/cloud_spec.rb +93 -89
  29. data/spec/unit/dsl/dsl_spec.rb +34 -34
  30. data/spec/unit/dsl/introspection_spec.rb +201 -189
  31. data/spec/unit/dsl/os_spec.rb +175 -175
  32. data/spec/unit/dsl/path_sanity_spec.rb +86 -86
  33. data/spec/unit/dsl/platform_family_spec.rb +235 -223
  34. data/spec/unit/dsl/platform_spec.rb +252 -238
  35. data/spec/unit/dsl/service_spec.rb +117 -117
  36. data/spec/unit/dsl/virtualization_spec.rb +75 -75
  37. data/spec/unit/dsl/which_spec.rb +171 -171
  38. data/spec/unit/dsl/windows_spec.rb +84 -84
  39. data/spec/unit/mash_spec.rb +51 -51
  40. data/spec/unit/parallel_map_spec.rb +156 -0
  41. metadata +26 -10
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef-utils/parallel_map"
20
+
21
+ using ChefUtils::ParallelMap
22
+
23
+ RSpec.describe ChefUtils::ParallelMap do
24
+
25
+ shared_examples_for "common parallel API tests" do
26
+
27
+ before(:each) do
28
+ ChefUtils::DefaultThreadPool.instance.instance_variable_set(:@pool, nil)
29
+ ChefUtils::DefaultThreadPool.instance.threads = threads
30
+ end
31
+
32
+ after(:each) do
33
+ ChefUtils::DefaultThreadPool.instance.instance_variable_set(:@pool, nil)
34
+ end
35
+
36
+ it "parallel_map runs in parallel" do
37
+ # this is implicitly also testing that we run in the caller when we exhaust threads by running threads+1
38
+ val = threads + 1
39
+ ret = []
40
+ start = Time.now
41
+ (1..val).parallel_map do |i|
42
+ loop do
43
+ if val == i
44
+ ret << i
45
+ val -= 1
46
+ break
47
+ end
48
+ # we spin for quite awhile to wait for very slow testers if we have to
49
+ if Time.now - start > 30
50
+ raise "timed out; deadlocked due to lack of parallelization?"
51
+ end
52
+
53
+ # need to sleep a tiny bit to let other threads schedule
54
+ sleep 0.000001
55
+ end
56
+ end
57
+ expected = (1..threads + 1).to_a.reverse
58
+ expect(ret).to eql(expected)
59
+ end
60
+
61
+ it "parallel_each runs in parallel" do
62
+ # this is implicitly also testing that we run in the caller when we exhaust threads by running threads+1
63
+ val = threads + 1
64
+ ret = []
65
+ start = Time.now
66
+ (1..val).parallel_each do |i|
67
+ loop do
68
+ if val == i
69
+ ret << i
70
+ val -= 1
71
+ break
72
+ end
73
+ # we spin for quite awhile to wait for very slow testers if we have to
74
+ if Time.now - start > 30
75
+ raise "timed out; deadlocked due to lack of parallelization?"
76
+ end
77
+
78
+ # need to sleep a tiny bit to let other threads schedule
79
+ sleep 0.000001
80
+ end
81
+ end
82
+ expected = (1..threads + 1).to_a.reverse
83
+ expect(ret).to eql(expected)
84
+ end
85
+
86
+ it "parallel_map throws exceptions" do
87
+ expect { (0..10).parallel_map { |i| raise "boom" } }.to raise_error(RuntimeError)
88
+ end
89
+
90
+ it "parallel_each throws exceptions" do
91
+ expect { (0..10).parallel_each { |i| raise "boom" } }.to raise_error(RuntimeError)
92
+ end
93
+
94
+ it "parallel_map runs" do
95
+ ans = Timeout.timeout(30) do
96
+ (1..10).parallel_map { |i| i }
97
+ end
98
+ expect(ans).to eql((1..10).to_a)
99
+ end
100
+
101
+ it "parallel_each runs" do
102
+ Timeout.timeout(30) do
103
+ (1..10).parallel_each { |i| i }
104
+ end
105
+ end
106
+
107
+ it "recursive parallel_map will not deadlock" do
108
+ ans = Timeout.timeout(30) do
109
+ (1..2).parallel_map { |i| (1..2).parallel_map { |i| i } }
110
+ end
111
+ expect(ans).to eql([[1, 2], [1, 2]])
112
+ end
113
+
114
+ it "recursive parallel_each will not deadlock" do
115
+ Timeout.timeout(30) do
116
+ (1..2).parallel_each { |i| (1..2).parallel_each { |i| i } }
117
+ end
118
+ end
119
+
120
+ it "parallel_map is lazy" do
121
+ ans = Timeout.timeout(30) do
122
+ (1..).lazy.parallel_map { |i| i }.first(5)
123
+ end
124
+ expect(ans).to eql((1..5).to_a)
125
+ end
126
+
127
+ it "parallel_each is lazy" do
128
+ Timeout.timeout(30) do
129
+ (1..).lazy.parallel_each { |i| i }.first(5)
130
+ end
131
+ end
132
+ end
133
+
134
+ context "with 10 threads" do
135
+ let(:threads) { 10 }
136
+ it_behaves_like "common parallel API tests"
137
+ end
138
+
139
+ context "with 0 threads" do
140
+ let(:threads) { 0 }
141
+ it_behaves_like "common parallel API tests"
142
+ end
143
+
144
+ context "with 1 threads" do
145
+ let(:threads) { 1 }
146
+ it_behaves_like "common parallel API tests"
147
+ end
148
+
149
+ context "flat_each" do
150
+ it "runs each over items which are nested one level" do
151
+ sum = 0
152
+ [ [ 1, 2 ], [3, 4]].flat_each { |i| sum += i }
153
+ expect(sum).to eql(10)
154
+ end
155
+ end
156
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.10.17
4
+ version: 17.10.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description:
14
28
  email:
15
29
  - oss@chef.io
@@ -38,6 +52,7 @@ files:
38
52
  - lib/chef-utils/dsl/windows.rb
39
53
  - lib/chef-utils/internal.rb
40
54
  - lib/chef-utils/mash.rb
55
+ - lib/chef-utils/parallel_map.rb
41
56
  - lib/chef-utils/version.rb
42
57
  - lib/chef-utils/version_string.rb
43
58
  - spec/spec_helper.rb
@@ -54,15 +69,16 @@ files:
54
69
  - spec/unit/dsl/which_spec.rb
55
70
  - spec/unit/dsl/windows_spec.rb
56
71
  - spec/unit/mash_spec.rb
57
- homepage: https://github.com/chef/chef/tree/master/chef-utils
72
+ - spec/unit/parallel_map_spec.rb
73
+ homepage: https://github.com/chef/chef/tree/main/chef-utils
58
74
  licenses:
59
75
  - Apache-2.0
60
76
  metadata:
61
77
  bug_tracker_uri: https://github.com/chef/chef/issues
62
- changelog_uri: https://github.com/chef/chef/blob/master/CHANGELOG.md
63
- documentation_uri: https://github.com/chef/chef/tree/master/chef-utils/README.md
64
- homepage_uri: https://github.com/chef/chef/tree/master/chef-utils
65
- source_code_uri: https://github.com/chef/chef/tree/master/chef-utils
78
+ changelog_uri: https://github.com/chef/chef/blob/main/CHANGELOG.md
79
+ documentation_uri: https://github.com/chef/chef/tree/main/chef-utils/README.md
80
+ homepage_uri: https://github.com/chef/chef/tree/main/chef-utils
81
+ source_code_uri: https://github.com/chef/chef/tree/main/chef-utils
66
82
  post_install_message:
67
83
  rdoc_options: []
68
84
  require_paths:
@@ -71,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
87
  requirements:
72
88
  - - ">="
73
89
  - !ruby/object:Gem::Version
74
- version: 2.6.0
90
+ version: '2.6'
75
91
  required_rubygems_version: !ruby/object:Gem::Requirement
76
92
  requirements:
77
93
  - - ">="
78
94
  - !ruby/object:Gem::Version
79
95
  version: '0'
80
96
  requirements: []
81
- rubygems_version: 3.1.4
97
+ rubygems_version: 3.2.32
82
98
  signing_key:
83
99
  specification_version: 4
84
100
  summary: Basic utility functions for Core Chef Infra development