bson 4.15.0 → 5.0.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.
- checksums.yaml +4 -4
- data/README.md +94 -10
- data/Rakefile +68 -39
- data/ext/bson/bson-native.h +12 -4
- data/ext/bson/extconf.rb +8 -3
- data/ext/bson/init.c +11 -11
- data/ext/bson/read.c +39 -9
- data/ext/bson/util.c +171 -16
- data/ext/bson/write.c +34 -39
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +58 -32
- data/lib/bson/big_decimal.rb +16 -6
- data/lib/bson/binary.rb +271 -129
- data/lib/bson/boolean.rb +1 -0
- data/lib/bson/code.rb +10 -12
- data/lib/bson/code_with_scope.rb +9 -11
- data/lib/bson/config.rb +1 -27
- data/lib/bson/date.rb +2 -1
- data/lib/bson/date_time.rb +2 -1
- data/lib/bson/db_pointer.rb +12 -13
- data/lib/bson/dbref.rb +11 -9
- data/lib/bson/decimal128/builder.rb +10 -9
- data/lib/bson/decimal128.rb +25 -111
- data/lib/bson/document.rb +1 -0
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error/bson_decode_error.rb +11 -0
- data/lib/bson/error/ext_json_parse_error.rb +11 -0
- data/lib/bson/error/illegal_key.rb +23 -0
- data/lib/bson/error/invalid_binary_type.rb +37 -0
- data/lib/bson/error/invalid_dbref_argument.rb +12 -0
- data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
- data/lib/bson/error/invalid_decimal128_range.rb +27 -0
- data/lib/bson/error/invalid_decimal128_string.rb +26 -0
- data/lib/bson/error/invalid_key.rb +24 -0
- data/lib/bson/error/invalid_object_id.rb +11 -0
- data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
- data/lib/bson/error/unrepresentable_precision.rb +19 -0
- data/lib/bson/error/unserializable_class.rb +13 -0
- data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
- data/lib/bson/error/unsupported_type.rb +11 -0
- data/lib/bson/error.rb +16 -28
- data/lib/bson/ext_json.rb +2 -1
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +3 -2
- data/lib/bson/hash.rb +128 -73
- data/lib/bson/int32.rb +17 -5
- data/lib/bson/int64.rb +17 -5
- data/lib/bson/integer.rb +4 -5
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +8 -10
- data/lib/bson/min_key.rb +8 -10
- data/lib/bson/nil_class.rb +1 -0
- data/lib/bson/object.rb +7 -27
- data/lib/bson/object_id.rb +84 -120
- data/lib/bson/open_struct.rb +3 -2
- data/lib/bson/regexp.rb +36 -65
- data/lib/bson/registry.rb +2 -6
- data/lib/bson/specialized.rb +2 -1
- data/lib/bson/string.rb +4 -27
- data/lib/bson/symbol.rb +23 -20
- data/lib/bson/time.rb +3 -2
- data/lib/bson/time_with_zone.rb +13 -1
- data/lib/bson/timestamp.rb +3 -2
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +15 -1
- data/lib/bson/version.rb +3 -1
- data/lib/bson.rb +3 -2
- data/spec/bson/array_spec.rb +19 -60
- data/spec/bson/big_decimal_spec.rb +16 -4
- data/spec/bson/binary_spec.rb +129 -81
- data/spec/bson/binary_uuid_spec.rb +1 -0
- data/spec/bson/boolean_spec.rb +1 -0
- data/spec/bson/byte_buffer_read_spec.rb +1 -0
- data/spec/bson/byte_buffer_spec.rb +1 -0
- data/spec/bson/byte_buffer_write_spec.rb +1 -0
- data/spec/bson/code_spec.rb +5 -3
- data/spec/bson/code_with_scope_spec.rb +5 -3
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +1 -0
- data/spec/bson/date_time_spec.rb +1 -0
- data/spec/bson/dbref_legacy_spec.rb +20 -3
- data/spec/bson/dbref_spec.rb +9 -9
- data/spec/bson/decimal128_spec.rb +40 -20
- data/spec/bson/document_as_spec.rb +1 -0
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/ext_json_parse_spec.rb +1 -0
- data/spec/bson/false_class_spec.rb +8 -0
- data/spec/bson/float_spec.rb +8 -3
- data/spec/bson/hash_as_spec.rb +1 -0
- data/spec/bson/hash_spec.rb +87 -75
- data/spec/bson/int32_spec.rb +21 -6
- data/spec/bson/int64_spec.rb +21 -6
- data/spec/bson/integer_spec.rb +45 -13
- data/spec/bson/json_spec.rb +1 -0
- data/spec/bson/max_key_spec.rb +5 -3
- data/spec/bson/min_key_spec.rb +5 -3
- data/spec/bson/nil_class_spec.rb +1 -0
- data/spec/bson/object_id_spec.rb +57 -4
- data/spec/bson/object_spec.rb +2 -1
- data/spec/bson/open_struct_spec.rb +14 -71
- data/spec/bson/raw_spec.rb +9 -15
- data/spec/bson/regexp_spec.rb +4 -3
- data/spec/bson/registry_spec.rb +2 -1
- data/spec/bson/string_spec.rb +13 -38
- data/spec/bson/symbol_raw_spec.rb +25 -0
- data/spec/bson/symbol_spec.rb +15 -18
- data/spec/bson/time_spec.rb +1 -0
- data/spec/bson/time_with_zone_spec.rb +1 -0
- data/spec/bson/timestamp_spec.rb +1 -0
- data/spec/bson/true_class_spec.rb +8 -0
- data/spec/bson/undefined_spec.rb +27 -0
- data/spec/bson_spec.rb +1 -0
- data/spec/runners/common_driver.rb +6 -5
- data/spec/runners/corpus.rb +6 -0
- data/spec/runners/corpus_legacy.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_tests/common_driver_spec.rb +9 -4
- data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
- data/spec/spec_tests/corpus_spec.rb +13 -3
- data/spec/spec_tests/data/corpus/binary.json +5 -0
- data/spec/spec_tests/data/corpus/code.json +13 -13
- data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
- data/spec/spec_tests/data/corpus/document.json +20 -0
- data/spec/spec_tests/data/corpus/symbol.json +7 -7
- data/spec/spec_tests/data/corpus/top.json +18 -3
- data/spec/support/shared_examples.rb +28 -5
- data/spec/support/spec_config.rb +1 -0
- data/spec/support/utils.rb +49 -1
- metadata +114 -164
- checksums.yaml.gz.sig +0 -0
- data/spec/shared/LICENSE +0 -20
- data/spec/shared/bin/get-mongodb-download-url +0 -17
- data/spec/shared/bin/s3-copy +0 -45
- data/spec/shared/bin/s3-upload +0 -69
- data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
- data/spec/shared/lib/mrss/cluster_config.rb +0 -231
- data/spec/shared/lib/mrss/constraints.rb +0 -386
- data/spec/shared/lib/mrss/docker_runner.rb +0 -271
- data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
- data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
- data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
- data/spec/shared/lib/mrss/utils.rb +0 -15
- data/spec/shared/share/Dockerfile.erb +0 -338
- data/spec/shared/share/haproxy-1.conf +0 -16
- data/spec/shared/share/haproxy-2.conf +0 -17
- data/spec/shared/shlib/distro.sh +0 -74
- data/spec/shared/shlib/server.sh +0 -367
- data/spec/shared/shlib/set_env.sh +0 -131
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -1
@@ -1,271 +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
|
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') do |v|
|
67
|
-
@options[:preload] = v
|
68
|
-
end
|
69
|
-
|
70
|
-
opts.on('-s', '--script=SCRIPT', 'Test script to invoke') do |v|
|
71
|
-
@options[:script] = v
|
72
|
-
end
|
73
|
-
|
74
|
-
opts.on('-i', '--interactive', 'Interactive mode - disable per-test timeouts') do |v|
|
75
|
-
@options[:interactive] = v
|
76
|
-
end
|
77
|
-
end.parse!
|
78
|
-
|
79
|
-
@env = Hash[ARGV.map do |arg|
|
80
|
-
arg.split('=', 2)
|
81
|
-
end]
|
82
|
-
|
83
|
-
@env['RVM_RUBY'] ||= 'ruby-2.7'
|
84
|
-
unless ruby =~ /^j?ruby-/
|
85
|
-
raise "RVM_RUBY option is not in expected format: #{ruby}"
|
86
|
-
end
|
87
|
-
|
88
|
-
@env['MONGODB_VERSION'] ||= '4.4'
|
89
|
-
end
|
90
|
-
|
91
|
-
def create_dockerfile
|
92
|
-
template_path = File.join(File.dirname(__FILE__), '../../share/Dockerfile.erb')
|
93
|
-
result = ERB.new(File.read(template_path)).result(binding)
|
94
|
-
File.open(dockerfile_path, 'w') do |f|
|
95
|
-
f << result
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def image_tag
|
100
|
-
options.fetch(:image_tag)
|
101
|
-
end
|
102
|
-
|
103
|
-
def dockerfile_path
|
104
|
-
options.fetch(:dockerfile_path)
|
105
|
-
end
|
106
|
-
|
107
|
-
def create_image
|
108
|
-
run_command(['docker', 'build',
|
109
|
-
'-t', image_tag,
|
110
|
-
'-f', dockerfile_path,
|
111
|
-
'.'])
|
112
|
-
end
|
113
|
-
|
114
|
-
BASE_TEST_COMMAND = %w(docker run --rm -i --tmpfs /tmpfs:exec).freeze
|
115
|
-
|
116
|
-
def run_tests
|
117
|
-
run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [image_tag] +
|
118
|
-
script.split(/\s+/))
|
119
|
-
end
|
120
|
-
|
121
|
-
def run_deployment
|
122
|
-
run_command(BASE_TEST_COMMAND + tty_arg + extra_env + [
|
123
|
-
'-e', %q`TEST_CMD=watch -x bash -c "ps awwxu |egrep 'mongo|ocsp'"`,
|
124
|
-
'-e', 'BIND_ALL=true',
|
125
|
-
] + port_forwards + [image_tag] + script.split(/\s+/))
|
126
|
-
end
|
127
|
-
|
128
|
-
def tty_arg
|
129
|
-
tty = File.open('/dev/stdin') do |f|
|
130
|
-
f.isatty
|
131
|
-
end
|
132
|
-
if tty
|
133
|
-
%w(-t --init)
|
134
|
-
else
|
135
|
-
[]
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def extra_env
|
140
|
-
if @options[:extra_env]
|
141
|
-
@options[:extra_env].map do |k, v|
|
142
|
-
# Here the value must not be escaped
|
143
|
-
['-e', "#{k}=#{v}"]
|
144
|
-
end.flatten
|
145
|
-
else
|
146
|
-
[]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def port_forwards
|
151
|
-
args = (0...num_exposed_ports).map do |i|
|
152
|
-
host_port = @options[:mongo_only] + i
|
153
|
-
container_port = 27017 + i
|
154
|
-
['-p', "#{host_port}:#{container_port}"]
|
155
|
-
end.flatten
|
156
|
-
|
157
|
-
if @env['OCSP_ALGORITHM'] && !@env['OCSP_VERIFIER']
|
158
|
-
args += %w(-p 8100:8100)
|
159
|
-
end
|
160
|
-
|
161
|
-
args
|
162
|
-
end
|
163
|
-
|
164
|
-
def run_command(cmd)
|
165
|
-
if pid = fork
|
166
|
-
Process.wait(pid)
|
167
|
-
unless $?.exitstatus == 0
|
168
|
-
raise "Process exited with code #{$?.exitstatus}"
|
169
|
-
end
|
170
|
-
else
|
171
|
-
exec(*cmd)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def distro
|
176
|
-
@options[:distro] || 'ubuntu1804'
|
177
|
-
end
|
178
|
-
|
179
|
-
BASE_IMAGES = {
|
180
|
-
'debian81' => 'debian:jessie',
|
181
|
-
'debian92' => 'debian:stretch',
|
182
|
-
'debian10' => 'debian:buster',
|
183
|
-
'ubuntu1404' => 'ubuntu:trusty',
|
184
|
-
'ubuntu1604' => 'ubuntu:xenial',
|
185
|
-
'ubuntu1804' => 'ubuntu:bionic',
|
186
|
-
'ubuntu2004' => 'ubuntu:focal',
|
187
|
-
'rhel62' => 'centos:6',
|
188
|
-
'rhel70' => 'centos:7',
|
189
|
-
}.freeze
|
190
|
-
|
191
|
-
def base_image
|
192
|
-
BASE_IMAGES[distro] or raise "Unknown distro: #{distro}"
|
193
|
-
end
|
194
|
-
|
195
|
-
def ruby
|
196
|
-
@env['RVM_RUBY']
|
197
|
-
end
|
198
|
-
|
199
|
-
def ruby_head?
|
200
|
-
ruby == 'ruby-head'
|
201
|
-
end
|
202
|
-
|
203
|
-
def system_ruby?
|
204
|
-
%w(1 true yes).include?(@env['SYSTEM_RUBY']&.downcase)
|
205
|
-
end
|
206
|
-
|
207
|
-
def server_version
|
208
|
-
@env['MONGODB_VERSION']
|
209
|
-
end
|
210
|
-
|
211
|
-
def script
|
212
|
-
@options[:script] || options.fetch(:default_script)
|
213
|
-
end
|
214
|
-
|
215
|
-
def debian?
|
216
|
-
distro =~ /debian|ubuntu/
|
217
|
-
end
|
218
|
-
|
219
|
-
def preload?
|
220
|
-
!!@options[:preload]
|
221
|
-
end
|
222
|
-
|
223
|
-
def interactive?
|
224
|
-
!!@options[:interactive]
|
225
|
-
end
|
226
|
-
|
227
|
-
def project_lib_subdir
|
228
|
-
options.fetch(:project_lib_subdir)
|
229
|
-
end
|
230
|
-
|
231
|
-
def server_download_url
|
232
|
-
@server_download_url ||= ServerVersionRegistry.new(server_version, distro).download_url
|
233
|
-
end
|
234
|
-
|
235
|
-
def libmongocrypt_path
|
236
|
-
case distro
|
237
|
-
when /ubuntu1604/
|
238
|
-
"./ubuntu1604/nocrypto/lib64/libmongocrypt.so"
|
239
|
-
when /ubuntu1804/
|
240
|
-
"./ubuntu1804-64/nocrypto/lib64/libmongocrypt.so"
|
241
|
-
when /debian92/
|
242
|
-
"./debian92/nocrypto/lib64/libmongocrypt.so"
|
243
|
-
else
|
244
|
-
raise "This script does not support running FLE tests on #{distro}. Use ubuntu1604, ubuntu1804 or debian92 instead"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
def expose?
|
249
|
-
!!@options[:mongo_only]
|
250
|
-
end
|
251
|
-
|
252
|
-
def fle?
|
253
|
-
%w(1 true yes).include?(@env['FLE']&.downcase)
|
254
|
-
end
|
255
|
-
|
256
|
-
def num_exposed_ports
|
257
|
-
case @env['TOPOLOGY'] || 'standalone'
|
258
|
-
when 'standalone'
|
259
|
-
1
|
260
|
-
when 'replica-set'
|
261
|
-
3
|
262
|
-
when 'sharded-cluster'
|
263
|
-
if @env['SINGLE_MONGOS']
|
264
|
-
1
|
265
|
-
else
|
266
|
-
2
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
@@ -1,200 +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)
|
88
|
-
events = if include_auth
|
89
|
-
started_events
|
90
|
-
else
|
91
|
-
non_auth_command_started_events
|
92
|
-
end
|
93
|
-
events.select! do |event|
|
94
|
-
event.command[command_name]
|
95
|
-
end
|
96
|
-
if events.length != 1
|
97
|
-
raise "Expected a single #{command_name} event but we have #{events.length}"
|
98
|
-
end
|
99
|
-
events.first
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
# Get the first succeeded event published for the name, and then delete it.
|
104
|
-
#
|
105
|
-
# @param [ String ] name The event name.
|
106
|
-
#
|
107
|
-
# @return [ Event ] The matching event.
|
108
|
-
def first_event(name)
|
109
|
-
cls = MAPPINGS[name]
|
110
|
-
if cls.nil?
|
111
|
-
raise ArgumentError, "Bogus event name #{name}"
|
112
|
-
end
|
113
|
-
matching = succeeded_events.find do |event|
|
114
|
-
cls === event
|
115
|
-
end
|
116
|
-
succeeded_events.delete(matching)
|
117
|
-
matching
|
118
|
-
end
|
119
|
-
|
120
|
-
# Event recording
|
121
|
-
|
122
|
-
# Cache the started event.
|
123
|
-
#
|
124
|
-
# @param [ Event ] event The event.
|
125
|
-
def started(event)
|
126
|
-
@mutex.synchronize do
|
127
|
-
started_events << event
|
128
|
-
all_events << event
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Cache the succeeded event.
|
133
|
-
#
|
134
|
-
# @param [ Event ] event The event.
|
135
|
-
def succeeded(event)
|
136
|
-
@mutex.synchronize do
|
137
|
-
succeeded_events << event
|
138
|
-
all_events << event
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Cache the failed event.
|
143
|
-
#
|
144
|
-
# @param [ Event ] event The event.
|
145
|
-
def failed(event)
|
146
|
-
@mutex.synchronize do
|
147
|
-
failed_events << event
|
148
|
-
all_events << event
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def published(event)
|
153
|
-
@mutex.synchronize do
|
154
|
-
published_events << event
|
155
|
-
all_events << event
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Clear all cached events.
|
160
|
-
def clear_events!
|
161
|
-
@all_events = []
|
162
|
-
@started_events = []
|
163
|
-
@succeeded_events = []
|
164
|
-
@failed_events = []
|
165
|
-
@published_events = []
|
166
|
-
self
|
167
|
-
end
|
168
|
-
end
|
169
|
-
# Only handles succeeded events correctly.
|
170
|
-
class PhasedEventSubscriber < EventSubscriber
|
171
|
-
def initialize
|
172
|
-
super
|
173
|
-
@phase_events = {}
|
174
|
-
end
|
175
|
-
|
176
|
-
def phase_finished(phase_index)
|
177
|
-
@phase_events[phase_index] = succeeded_events
|
178
|
-
@succeeded_events = []
|
179
|
-
end
|
180
|
-
|
181
|
-
def phase_events(phase_index)
|
182
|
-
@phase_events[phase_index]
|
183
|
-
end
|
184
|
-
|
185
|
-
def event_count
|
186
|
-
@phase_events.inject(0) do |sum, event|
|
187
|
-
sum + event.length
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
class VerboseEventSubscriber < EventSubscriber
|
193
|
-
%w(started succeeded failed published).each do |meth|
|
194
|
-
define_method(meth) do |event|
|
195
|
-
puts event.summary
|
196
|
-
super(event)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
module Mrss
|
5
|
-
module LiteConstraints
|
6
|
-
|
7
|
-
# Constrain tests that use TimeoutInterrupt to MRI (and Unix).
|
8
|
-
def require_mri
|
9
|
-
before(:all) do
|
10
|
-
unless SpecConfig.instance.mri?
|
11
|
-
skip "MRI required, we have #{SpecConfig.instance.platform}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def require_jruby
|
17
|
-
before(:all) do
|
18
|
-
unless BSON::Environment.jruby?
|
19
|
-
skip "JRuby required, we have #{SpecConfig.instance.platform}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# This is for marking tests that fail on JRuby that should
|
25
|
-
# in principle work (as opposed to being fundamentally incompatible
|
26
|
-
# with JRuby).
|
27
|
-
# Often times these failures happen only in Evergreen.
|
28
|
-
def fails_on_jruby(version=nil)
|
29
|
-
before(:all) do
|
30
|
-
if BSON::Environment.jruby?
|
31
|
-
if version
|
32
|
-
min_parts = version.split('.').map(&:to_i)
|
33
|
-
actual_parts = JRUBY_VERSION.split('.').map(&:to_i)[0...min_parts.length]
|
34
|
-
actual = actual_parts.join('.')
|
35
|
-
if actual <= version
|
36
|
-
skip "Fails on jruby through #{version}"
|
37
|
-
end
|
38
|
-
else
|
39
|
-
skip "Fails on jruby"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Indicates that the respective test uses the internet in some capacity,
|
46
|
-
# for example the test resolves SRV DNS records.
|
47
|
-
def require_external_connectivity
|
48
|
-
before(:all) do
|
49
|
-
if ENV['EXTERNAL_DISABLED']
|
50
|
-
skip "Test requires external connectivity"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def require_mongo_kerberos
|
56
|
-
before(:all) do
|
57
|
-
# TODO Use a more generic environment variable name if/when
|
58
|
-
# Mongoid tests get Kerberos configurations.
|
59
|
-
unless %w(1 yes true).include?(ENV['MONGO_RUBY_DRIVER_KERBEROS']&.downcase)
|
60
|
-
skip 'Set MONGO_RUBY_DRIVER_KERBEROS=1 in environment to run Kerberos unit tests'
|
61
|
-
end
|
62
|
-
require 'mongo_kerberos'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def require_linting
|
67
|
-
before(:all) do
|
68
|
-
unless Mongo::Lint.enabled?
|
69
|
-
skip "Linting is not enabled"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Some tests will fail if linting is enabled:
|
75
|
-
# 1. Tests that pass invalid options to client, etc. which the linter
|
76
|
-
# rejects.
|
77
|
-
# 2. Tests that set expectations on topologies, server descriptions, etc.
|
78
|
-
# (since setting expectations requires mutating said objects, and when
|
79
|
-
# linting is on those objects are frozen).
|
80
|
-
def require_no_linting
|
81
|
-
before(:all) do
|
82
|
-
if Mongo::Lint.enabled?
|
83
|
-
skip "Linting is enabled"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def require_libmongocrypt
|
89
|
-
before(:all) do
|
90
|
-
unless ENV['LIBMONGOCRYPT_PATH']
|
91
|
-
skip 'Test requires path to libmongocrypt to be specified in LIBMONGOCRYPT_PATH env variable'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def require_no_libmongocrypt
|
97
|
-
before(:all) do
|
98
|
-
if ENV['LIBMONGOCRYPT_PATH']
|
99
|
-
skip 'Test requires libmongocrypt to not be configured'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def require_aws_auth
|
105
|
-
before(:all) do
|
106
|
-
unless (ENV['AUTH'] || '') =~ /^aws/
|
107
|
-
skip 'This test requires AUTH=aws* and an appropriately configured runtime environment'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def require_ec2_host
|
113
|
-
before(:all) do
|
114
|
-
if $have_aws.nil?
|
115
|
-
$have_aws = begin
|
116
|
-
require 'open-uri'
|
117
|
-
begin
|
118
|
-
Timeout.timeout(3.81) do
|
119
|
-
URI.parse('http://169.254.169.254/latest/meta-data/profile').open.read
|
120
|
-
end
|
121
|
-
true
|
122
|
-
# When trying to use the EC2 metadata endpoint on ECS:
|
123
|
-
# Errno::EINVAL: Failed to open TCP connection to 169.254.169.254:80 (Invalid argument - connect(2) for "169.254.169.254" port 80)
|
124
|
-
rescue Timeout::Error, Errno::ETIMEDOUT, Errno::EINVAL, OpenURI::HTTPError => $aws_error
|
125
|
-
false
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
unless $have_aws
|
130
|
-
skip "EC2 instance metadata is not available - assuming not running on an EC2 instance: #{$aws_error.class}: #{$aws_error}"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def require_stress
|
136
|
-
before(:all) do
|
137
|
-
if !SpecConfig.instance.stress?
|
138
|
-
skip 'Set STRESS=1 in environment to run stress tests'
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def require_fork
|
144
|
-
before(:all) do
|
145
|
-
if !SpecConfig.instance.fork?
|
146
|
-
skip 'Set FORK=1 in environment to run fork tests'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def require_ocsp
|
152
|
-
before(:all) do
|
153
|
-
if !SpecConfig.instance.ocsp?
|
154
|
-
skip 'Set OCSP=1 in environment to run OCSP tests'
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def require_ocsp_verifier
|
160
|
-
before(:all) do
|
161
|
-
if !SpecConfig.instance.ocsp_verifier?
|
162
|
-
skip 'Set OCSP_VERIFIER=1 in environment to run OCSP verifier tests'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def require_ocsp_connectivity
|
168
|
-
before(:all) do
|
169
|
-
if !SpecConfig.instance.ocsp_connectivity?
|
170
|
-
skip 'Set OCSP_CONNECTIVITY=pass or OCSP_CONNECTIVITY=fail in environment to run OCSP connectivity tests'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def require_active_support
|
176
|
-
before(:all) do
|
177
|
-
if !SpecConfig.instance.active_support?
|
178
|
-
skip 'This test requires ActiveSupport; set WITH_ACTIVE_SUPPORT=1 in environment'
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def no_active_support
|
184
|
-
before(:all) do
|
185
|
-
if SpecConfig.instance.active_support?
|
186
|
-
skip 'This test requires no ActiveSupport; unset WITH_ACTIVE_SUPPORT in environment'
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|