bson 5.0.0-java → 5.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,298 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: utf-8
3
-
4
- require 'optparse'
5
- require 'erb'
6
- autoload :Dotenv, 'dotenv'
7
-
8
- module Mrss
9
- autoload :ServerVersionRegistry, 'mrss/server_version_registry'
10
-
11
- class DockerRunner
12
- def initialize(**opts)
13
- # These options are required:
14
- opts.fetch(:image_tag)
15
- opts.fetch(:dockerfile_path)
16
- opts.fetch(:default_script)
17
- opts.fetch(:project_lib_subdir)
18
-
19
- @options = opts.merge(preload: true)
20
- end
21
-
22
- attr_reader :options
23
-
24
- def run
25
- process_arguments
26
- unless @options[:exec_only]
27
- create_dockerfile
28
- create_image
29
- end
30
- if @options[:mongo_only]
31
- run_deployment
32
- else
33
- run_tests
34
- end
35
- end
36
-
37
- private
38
-
39
- def process_arguments
40
- #@options = {}
41
- OptionParser.new do |opts|
42
- opts.banner = "Usage: test-on-docker [-d distro] [evergreen_key=value ...]"
43
-
44
- opts.on("-a", "--add-env=PATH", "Load environment variables from PATH in .env format") do |path|
45
- @options[:extra_env] ||= {}
46
- unless File.exist?(path)
47
- raise "-a option references nonexistent file #{path}"
48
- end
49
- Dotenv.parse(path).each do |k, v|
50
- @options[:extra_env][k] = v
51
- end
52
- end
53
-
54
- opts.on("-d", "--distro=DISTRO", "Distro to use") do |v|
55
- @options[:distro] = v
56
- end
57
-
58
- opts.on('-e', '--exec-only', 'Execute tests using existing Dockerfile (for offline user)') do |v|
59
- @options[:exec_only] = v
60
- end
61
-
62
- opts.on('-m', '--mongo-only=PORT', 'Start the MongoDB deployment and expose it to host on ports starting with PORT') do |v|
63
- @options[:mongo_only] = v.to_i
64
- end
65
-
66
- opts.on('-p', '--preload', 'Preload Ruby toolchain and server binaries in docker (default)') do |v|
67
- @options[:preload] = v
68
- end
69
-
70
- opts.on('-P', '--no-preload', 'Do not preload Ruby toolchain and server binaries in docker') do
71
- @options[:preload] = false
72
- end
73
-
74
- opts.on('-s', '--script=SCRIPT', 'Test script to invoke') do |v|
75
- @options[:script] = v
76
- end
77
-
78
- opts.on('-i', '--interactive', 'Interactive mode - disable per-test timeouts') do |v|
79
- @options[:interactive] = v
80
- end
81
- end.parse!
82
-
83
- @env = Hash[ARGV.map do |arg|
84
- arg.split('=', 2)
85
- end]
86
-
87
- @env['RVM_RUBY'] ||= 'ruby-2.7'
88
- unless ruby =~ /^j?ruby-/
89
- raise "RVM_RUBY option is not in expected format: #{ruby}"
90
- end
91
-
92
- @env['MONGODB_VERSION'] ||= '4.4'
93
- end
94
-
95
- def create_dockerfile
96
- template_path = File.join(File.dirname(__FILE__), '../../share/Dockerfile.erb')
97
- result = ERB.new(File.read(template_path)).result(binding)
98
- File.open(dockerfile_path, 'w') do |f|
99
- f << result
100
- end
101
- end
102
-
103
- def image_tag
104
- options.fetch(:image_tag)
105
- end
106
-
107
- def dockerfile_path
108
- options.fetch(:dockerfile_path)
109
- end
110
-
111
- def create_image
112
- run_command(['docker', 'build',
113
- '-t', image_tag,
114
- '-f', dockerfile_path,
115
- '.'])
116
- end
117
-
118
- BASE_TEST_COMMAND = %w(docker run --rm -i --tmpfs /tmpfs:exec).freeze
119
-
120
- def run_tests
121
- run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [image_tag] +
122
- script.split(/\s+/))
123
- end
124
-
125
- def run_deployment
126
- run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [
127
- '-e', %q`TEST_CMD=watch -x bash -c "ps awwxu |egrep 'mongo|ocsp'"`,
128
- '-e', 'BIND_ALL=true',
129
- ] + port_forwards + [image_tag] + script.split(/\s+/))
130
- end
131
-
132
- def tty_arg
133
- tty = File.open('/dev/stdin') do |f|
134
- f.isatty
135
- end
136
- if tty
137
- %w(-t --init)
138
- else
139
- []
140
- end
141
- end
142
-
143
- def extra_env
144
- if @options[:extra_env]
145
- @options[:extra_env].map do |k, v|
146
- # Here the value must not be escaped
147
- ['-e', "#{k}=#{v}"]
148
- end.flatten
149
- else
150
- []
151
- end
152
- end
153
-
154
- def port_forwards
155
- args = (0...num_exposed_ports).map do |i|
156
- host_port = @options[:mongo_only] + i
157
- container_port = 27017 + i
158
- ['-p', "#{host_port}:#{container_port}"]
159
- end.flatten
160
-
161
- if @env['OCSP_ALGORITHM'] && !@env['OCSP_VERIFIER']
162
- args += %w(-p 8100:8100)
163
- end
164
-
165
- args
166
- end
167
-
168
- def run_command(cmd)
169
- if pid = fork
170
- Process.wait(pid)
171
- unless $?.exitstatus == 0
172
- raise "Process exited with code #{$?.exitstatus}"
173
- end
174
- else
175
- exec(*cmd)
176
- end
177
- end
178
-
179
- def distro
180
- @options[:distro] || if app_tests?
181
- 'ubuntu2004'
182
- else
183
- case server_version
184
- when '3.6'
185
- 'debian9'
186
- when '4.0', '4.2'
187
- 'ubuntu1804'
188
- else
189
- 'ubuntu2004'
190
- end
191
- end
192
- end
193
-
194
- BASE_IMAGES = {
195
- 'debian81' => 'debian:jessie',
196
- 'debian92' => 'debian:stretch',
197
- 'debian10' => 'debian:buster',
198
- 'debian11' => 'debian:bullseye',
199
- 'ubuntu1404' => 'ubuntu:trusty',
200
- 'ubuntu1604' => 'ubuntu:xenial',
201
- 'ubuntu1804' => 'ubuntu:bionic',
202
- 'ubuntu2004' => 'ubuntu:focal',
203
- 'ubuntu2204' => 'ubuntu:jammy',
204
- 'rhel62' => 'centos:6',
205
- 'rhel70' => 'centos:7',
206
- 'rhel80' => 'rockylinux:8',
207
- }.freeze
208
-
209
- def base_image
210
- BASE_IMAGES[distro] or raise "Unknown distro: #{distro}"
211
- end
212
-
213
- def ruby
214
- @env['RVM_RUBY']
215
- end
216
-
217
- def ruby_head?
218
- ruby == 'ruby-head'
219
- end
220
-
221
- def system_ruby?
222
- %w(1 true yes).include?(@env['SYSTEM_RUBY']&.downcase)
223
- end
224
-
225
- def server_version
226
- @env['MONGODB_VERSION']
227
- end
228
-
229
- def script
230
- @options[:script] || options.fetch(:default_script)
231
- end
232
-
233
- def debian?
234
- distro =~ /debian|ubuntu/
235
- end
236
-
237
- def ubuntu?
238
- distro=~ /ubuntu/
239
- end
240
-
241
- def preload?
242
- !!@options[:preload]
243
- end
244
-
245
- def interactive?
246
- !!@options[:interactive]
247
- end
248
-
249
- def project_lib_subdir
250
- options.fetch(:project_lib_subdir)
251
- end
252
-
253
- def server_download_url
254
- @server_download_url ||= ServerVersionRegistry.new(server_version, distro).download_url
255
- end
256
-
257
- def libmongocrypt_path
258
- case distro
259
- when /ubuntu1604/
260
- "./ubuntu1604/nocrypto/lib64/libmongocrypt.so"
261
- when /ubuntu1804/
262
- "./ubuntu1804-64/nocrypto/lib64/libmongocrypt.so"
263
- when /debian92/
264
- "./debian92/nocrypto/lib64/libmongocrypt.so"
265
- else
266
- raise "This script does not support running FLE tests on #{distro}. Use ubuntu1604, ubuntu1804 or debian92 instead"
267
- end
268
- end
269
-
270
- def expose?
271
- !!@options[:mongo_only]
272
- end
273
-
274
- def fle?
275
- %w(1 true yes).include?(@env['FLE']&.downcase)
276
- end
277
-
278
- # Mongoid
279
- def app_tests?
280
- %w(1 true yes).include?(@env['APP_TESTS']&.downcase)
281
- end
282
-
283
- def num_exposed_ports
284
- case @env['TOPOLOGY'] || 'standalone'
285
- when 'standalone'
286
- 1
287
- when 'replica-set'
288
- 3
289
- when 'sharded-cluster'
290
- if @env['SINGLE_MONGOS']
291
- 1
292
- else
293
- 2
294
- end
295
- end
296
- end
297
- end
298
- end
@@ -1,51 +0,0 @@
1
- autoload :YAML, 'yaml'
2
- require 'erubi'
3
- require 'erubi/capture_end'
4
- require 'tilt'
5
-
6
- module Mrss
7
- module EgConfigUtils
8
-
9
- DEBIAN_FOR_RUBY = {
10
- 'ruby-2.3' => 'debian92',
11
- 'ruby-2.4' => 'debian92',
12
- 'ruby-2.5' => 'debian10',
13
- 'ruby-2.6' => 'debian10',
14
- 'ruby-2.7' => 'debian10',
15
- 'ruby-3.0' => 'debian10',
16
- }
17
-
18
- def standard_debian_rubies(rubies, key: nil, &block)
19
- rubies.flatten!
20
- text = block.call
21
- contents = YAML.load(text)
22
- out = rubies.map do |ruby|
23
- contents.merge(
24
- 'matrix_name' => "#{contents['matrix_name']} - #{ruby}",
25
- 'matrix_spec' => contents['matrix_spec'].merge(
26
- 'ruby' => ruby,
27
- key || 'os' => DEBIAN_FOR_RUBY.fetch(ruby),
28
- ),
29
- )
30
- end.to_yaml
31
- text =~ /\A\n?(\s+)/
32
- unless text
33
- raise "Couldn't figure out indentation level"
34
- end
35
- indent = ' ' * ($1.length - 2)
36
- "\n" + out.sub(/\A---.*\n/, indent).gsub("\n", "\n#{indent}")
37
- end
38
-
39
- def transform_config(template_path, context)
40
- Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(context)
41
- end
42
-
43
- def generated_file_warning
44
- <<-EOT
45
- # GENERATED FILE - DO NOT EDIT.
46
- # Run ./.evergreen/update-evergreen-configs to regenerate this file.
47
-
48
- EOT
49
- end
50
- end
51
- end
@@ -1,210 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mrss
4
- # Test event subscriber.
5
- class EventSubscriber
6
-
7
- # The mappings of event names to types.
8
- MAPPINGS = {
9
- 'topology_opening_event' => Mongo::Monitoring::Event::TopologyOpening,
10
- 'topology_description_changed_event' => Mongo::Monitoring::Event::TopologyChanged,
11
- 'topology_closed_event' => Mongo::Monitoring::Event::TopologyClosed,
12
- 'server_opening_event' => Mongo::Monitoring::Event::ServerOpening,
13
- 'server_description_changed_event' => Mongo::Monitoring::Event::ServerDescriptionChanged,
14
- 'server_closed_event' => Mongo::Monitoring::Event::ServerClosed
15
- }.freeze
16
-
17
- attr_reader :all_events
18
-
19
- attr_reader :started_events
20
-
21
- attr_reader :succeeded_events
22
-
23
- attr_reader :failed_events
24
-
25
- attr_reader :published_events
26
-
27
- # @param [ String ] name Optional name for the event subscriber.
28
- def initialize(name: nil)
29
- @mutex = Mutex.new
30
- clear_events!
31
- @name = name
32
- end
33
-
34
- def to_s
35
- %Q`#<EventSubscriber:#{@name ? "\"#{@name}\"" : '%x' % object_id} \
36
- started=#{started_events.length} \
37
- succeeded=#{succeeded_events.length} \
38
- failed=#{failed_events.length} \
39
- published=#{published_events.length}>`
40
- end
41
-
42
- alias :inspect :to_s
43
-
44
- # Event retrieval
45
-
46
- def select_started_events(cls)
47
- started_events.select do |event|
48
- event.is_a?(cls)
49
- end
50
- end
51
-
52
- def select_succeeded_events(cls)
53
- succeeded_events.select do |event|
54
- event.is_a?(cls)
55
- end
56
- end
57
-
58
- def select_completed_events(*classes)
59
- (succeeded_events + failed_events).select do |event|
60
- classes.any? { |c| c === event }
61
- end
62
- end
63
-
64
- def select_published_events(cls)
65
- published_events.select do |event|
66
- event.is_a?(cls)
67
- end
68
- end
69
-
70
- # Filters command started events for the specified command name.
71
- def command_started_events(command_name)
72
- started_events.select do |event|
73
- event.command[command_name]
74
- end
75
- end
76
-
77
- def non_auth_command_started_events
78
- started_events.reject do |event|
79
- %w(authenticate getnonce saslSstart saslContinue).any? do |cmd|
80
- event.command[cmd]
81
- end
82
- end
83
- end
84
-
85
- # Locates command stated events for the specified command name,
86
- # asserts that there is exactly one such event, and returns it.
87
- def single_command_started_event(command_name, include_auth: false, database_name: nil)
88
- events = if include_auth
89
- started_events
90
- else
91
- non_auth_command_started_events
92
- end
93
- get_one_event(events, command_name, 'started', database_name: database_name)
94
- end
95
-
96
- # Locates command succeeded events for the specified command name,
97
- # asserts that there is exactly one such event, and returns it.
98
- def single_command_succeeded_event(command_name, database_name: nil)
99
- get_one_event(succeeded_events, command_name, 'succeeded', database_name: database_name)
100
- end
101
-
102
- def get_one_event(events, command_name, kind, database_name: nil)
103
- events = events.select do |event|
104
- event.command_name == command_name and
105
- database_name.nil? || database_name == event.database_name
106
- end
107
- if events.length != 1
108
- raise "Expected a single '#{command_name}' #{kind} event#{database_name ? " for '#{database_name}'" : ''} but we have #{events.length}"
109
- end
110
- events.first
111
- end
112
-
113
- # Get the first succeeded event published for the name, and then delete it.
114
- #
115
- # @param [ String ] name The event name.
116
- #
117
- # @return [ Event ] The matching event.
118
- def first_event(name)
119
- cls = MAPPINGS[name]
120
- if cls.nil?
121
- raise ArgumentError, "Bogus event name #{name}"
122
- end
123
- matching = succeeded_events.find do |event|
124
- cls === event
125
- end
126
- succeeded_events.delete(matching)
127
- matching
128
- end
129
-
130
- # Event recording
131
-
132
- # Cache the started event.
133
- #
134
- # @param [ Event ] event The event.
135
- def started(event)
136
- @mutex.synchronize do
137
- started_events << event
138
- all_events << event
139
- end
140
- end
141
-
142
- # Cache the succeeded event.
143
- #
144
- # @param [ Event ] event The event.
145
- def succeeded(event)
146
- @mutex.synchronize do
147
- succeeded_events << event
148
- all_events << event
149
- end
150
- end
151
-
152
- # Cache the failed event.
153
- #
154
- # @param [ Event ] event The event.
155
- def failed(event)
156
- @mutex.synchronize do
157
- failed_events << event
158
- all_events << event
159
- end
160
- end
161
-
162
- def published(event)
163
- @mutex.synchronize do
164
- published_events << event
165
- all_events << event
166
- end
167
- end
168
-
169
- # Clear all cached events.
170
- def clear_events!
171
- @all_events = []
172
- @started_events = []
173
- @succeeded_events = []
174
- @failed_events = []
175
- @published_events = []
176
- self
177
- end
178
- end
179
- # Only handles succeeded events correctly.
180
- class PhasedEventSubscriber < EventSubscriber
181
- def initialize
182
- super
183
- @phase_events = {}
184
- end
185
-
186
- def phase_finished(phase_index)
187
- @phase_events[phase_index] = succeeded_events
188
- @succeeded_events = []
189
- end
190
-
191
- def phase_events(phase_index)
192
- @phase_events[phase_index]
193
- end
194
-
195
- def event_count
196
- @phase_events.inject(0) do |sum, event|
197
- sum + event.length
198
- end
199
- end
200
- end
201
-
202
- class VerboseEventSubscriber < EventSubscriber
203
- %w(started succeeded failed published).each do |meth|
204
- define_method(meth) do |event|
205
- puts event.summary
206
- super(event)
207
- end
208
- end
209
- end
210
- end