bson 4.12.0-java → 4.14.1-java
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
- checksums.yaml.gz.sig +0 -0
- data/README.md +4 -7
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +2 -1
- data/lib/bson/big_decimal.rb +67 -0
- data/lib/bson/binary.rb +5 -3
- data/lib/bson/boolean.rb +2 -1
- data/lib/bson/code.rb +2 -1
- data/lib/bson/code_with_scope.rb +2 -1
- data/lib/bson/config.rb +1 -0
- data/lib/bson/date.rb +1 -0
- data/lib/bson/date_time.rb +1 -0
- data/lib/bson/db_pointer.rb +2 -1
- data/lib/bson/dbref.rb +152 -0
- data/lib/bson/decimal128/builder.rb +27 -20
- data/lib/bson/decimal128.rb +27 -12
- data/lib/bson/document.rb +18 -0
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error.rb +7 -0
- data/lib/bson/ext_json.rb +16 -11
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +21 -32
- data/lib/bson/hash.rb +15 -6
- data/lib/bson/int32.rb +3 -2
- data/lib/bson/int64.rb +3 -2
- data/lib/bson/integer.rb +3 -2
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +3 -2
- data/lib/bson/min_key.rb +3 -2
- data/lib/bson/nil_class.rb +2 -1
- data/lib/bson/object.rb +1 -0
- data/lib/bson/object_id.rb +4 -3
- data/lib/bson/open_struct.rb +1 -0
- data/lib/bson/regexp.rb +17 -6
- data/lib/bson/registry.rb +1 -0
- data/lib/bson/specialized.rb +1 -0
- data/lib/bson/string.rb +3 -2
- data/lib/bson/symbol.rb +2 -1
- data/lib/bson/time.rb +4 -3
- data/lib/bson/time_with_zone.rb +1 -0
- data/lib/bson/timestamp.rb +3 -2
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +2 -1
- data/lib/bson/version.rb +2 -1
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +8 -5
- data/spec/README.md +14 -0
- data/spec/bson/big_decimal_spec.rb +316 -0
- data/spec/bson/dbref_legacy_spec.rb +169 -0
- data/spec/bson/dbref_spec.rb +487 -0
- data/spec/bson/decimal128_spec.rb +16 -0
- data/spec/bson/document_as_spec.rb +46 -0
- data/spec/bson/document_spec.rb +7 -1
- data/spec/bson/ext_json_parse_spec.rb +37 -0
- data/spec/bson/hash_as_spec.rb +57 -0
- data/spec/bson/hash_spec.rb +32 -0
- data/spec/bson/int64_spec.rb +4 -24
- data/spec/bson/raw_spec.rb +7 -1
- data/spec/bson/regexp_spec.rb +52 -0
- data/spec/runners/common_driver.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +386 -0
- data/spec/shared/lib/mrss/docker_runner.rb +271 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +338 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +367 -0
- data/spec/shared/shlib/set_env.sh +131 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/spec_tests/common_driver_spec.rb +2 -1
- data/spec/spec_tests/data/corpus/binary.json +18 -1
- data/spec/spec_tests/data/corpus/dbref.json +21 -1
- data/spec/spec_tests/data/corpus/document.json +4 -0
- data/spec/spec_tests/data/corpus/regex.json +2 -2
- data/spec/spec_tests/data/corpus/top.json +20 -9
- data.tar.gz.sig +0 -0
- metadata +141 -89
- metadata.gz.sig +0 -0
@@ -0,0 +1,200 @@
|
|
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
|
@@ -0,0 +1,191 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
autoload :JSON, 'json'
|
5
|
+
require 'open-uri'
|
6
|
+
|
7
|
+
module Mrss
|
8
|
+
class ServerVersionRegistry
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class UnknownVersion < Error
|
13
|
+
end
|
14
|
+
|
15
|
+
class MissingDownloadUrl < Error
|
16
|
+
end
|
17
|
+
|
18
|
+
class BrokenDownloadUrl < Error
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(desired_version, arch)
|
22
|
+
@desired_version, @arch = desired_version, arch
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :desired_version, :arch
|
26
|
+
|
27
|
+
def download_url
|
28
|
+
@download_url ||= begin
|
29
|
+
version, version_ok = detect_version(current_catalog)
|
30
|
+
if version.nil?
|
31
|
+
version, full_version_ok = detect_version(full_catalog)
|
32
|
+
version_ok ||= full_version_ok
|
33
|
+
end
|
34
|
+
if version.nil?
|
35
|
+
if version_ok
|
36
|
+
raise MissingDownloadUrl, "No downloads for version #{desired_version}"
|
37
|
+
else
|
38
|
+
raise UnknownVersion, "No version #{desired_version}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
dl = version['downloads'].detect do |dl|
|
42
|
+
dl['archive']['url'].index("enterprise-#{arch}") &&
|
43
|
+
dl['arch'] == 'x86_64'
|
44
|
+
end
|
45
|
+
unless dl
|
46
|
+
raise MissingDownloadUrl, "No download for #{arch} for #{version['version']}"
|
47
|
+
end
|
48
|
+
url = dl['archive']['url']
|
49
|
+
end
|
50
|
+
rescue MissingDownloadUrl
|
51
|
+
if %w(2.6 3.0).include?(desired_version) && arch == 'ubuntu1604'
|
52
|
+
# 2.6 and 3.0 are only available for ubuntu1204 and ubuntu1404.
|
53
|
+
# Those ubuntus have ancient Pythons that don't work due to not
|
54
|
+
# implementing recent TLS protocols.
|
55
|
+
# Because of this we test on ubuntu1604 which has a newer Python.
|
56
|
+
# But we still need to retrieve ubuntu1404-targeting builds.
|
57
|
+
url = self.class.new('3.2', arch).download_url
|
58
|
+
unless url.include?('3.2.')
|
59
|
+
raise 'URL not in expected format'
|
60
|
+
end
|
61
|
+
url = case desired_version
|
62
|
+
when '2.6'
|
63
|
+
url.sub(/\b3\.2\.\d+/, '2.6.12')
|
64
|
+
when '3.0'
|
65
|
+
url.sub(/\b3\.2\.\d+/, '3.0.15')
|
66
|
+
else
|
67
|
+
raise NotImplementedError
|
68
|
+
end.sub('ubuntu1604', 'ubuntu1404')
|
69
|
+
else
|
70
|
+
raise
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def uri_open(*args)
|
77
|
+
if RUBY_VERSION < '2.5'
|
78
|
+
open(*args)
|
79
|
+
else
|
80
|
+
URI.open(*args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def detect_version(catalog)
|
85
|
+
candidate_versions = catalog['versions'].select do |version|
|
86
|
+
version['version'].start_with?(desired_version) &&
|
87
|
+
!version['version'].include?('-')
|
88
|
+
end
|
89
|
+
version_ok = !candidate_versions.empty?
|
90
|
+
# Sometimes the download situation is borked and there is a release
|
91
|
+
# with no downloads... skip those.
|
92
|
+
version = candidate_versions.detect do |version|
|
93
|
+
!version['downloads'].empty?
|
94
|
+
end
|
95
|
+
# Allow RC releases if there isn't a GA release.
|
96
|
+
if version.nil?
|
97
|
+
candidate_versions = catalog['versions'].select do |version|
|
98
|
+
version['version'].start_with?(desired_version)
|
99
|
+
end
|
100
|
+
version_ok ||= !candidate_versions.empty?
|
101
|
+
version = candidate_versions.detect do |version|
|
102
|
+
!version['downloads'].empty?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
[version, version_ok]
|
106
|
+
end
|
107
|
+
|
108
|
+
def current_catalog
|
109
|
+
@current_catalog ||= begin
|
110
|
+
JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def full_catalog
|
115
|
+
@full_catalog ||= begin
|
116
|
+
JSON.load(uri_open('http://downloads.mongodb.org/full.json').read)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
autoload :JSON, 'json'
|
5
|
+
autoload :FileUtils, 'fileutils'
|
6
|
+
autoload :Find, 'find'
|
7
|
+
|
8
|
+
module Mrss
|
9
|
+
|
10
|
+
autoload :ChildProcessHelper, 'mrss/child_process_helper'
|
11
|
+
|
12
|
+
# Organizes and runs all of the tests in the test suite in batches.
|
13
|
+
#
|
14
|
+
# Organizing the tests in batches serves two purposes:
|
15
|
+
#
|
16
|
+
# 1. This allows running unit tests before integration tests, therefore
|
17
|
+
# in theory revealing failures quicker on average.
|
18
|
+
# 2. This allows running some tests that have high intermittent failure rate
|
19
|
+
# in their own test process.
|
20
|
+
#
|
21
|
+
# This class aggregates RSpec results after the test runs.
|
22
|
+
class SpecOrganizer
|
23
|
+
|
24
|
+
class BucketsNotPrioritized < StandardError
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(root: nil, classifiers:, priority_order:,
|
28
|
+
spec_root: nil, rspec_json_path: nil, rspec_all_json_path: nil,
|
29
|
+
randomize: false
|
30
|
+
)
|
31
|
+
@spec_root = spec_root || File.join(root, 'spec')
|
32
|
+
@classifiers = classifiers
|
33
|
+
@priority_order = priority_order
|
34
|
+
@rspec_json_path = rspec_json_path || File.join(root, 'tmp/rspec.json')
|
35
|
+
@rspec_all_json_path = rspec_all_json_path || File.join(root, 'tmp/rspec-all.json')
|
36
|
+
@randomize = !!randomize
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :spec_root, :classifiers, :priority_order
|
40
|
+
attr_reader :rspec_json_path, :rspec_all_json_path
|
41
|
+
|
42
|
+
def randomize?
|
43
|
+
@randomize
|
44
|
+
end
|
45
|
+
|
46
|
+
def seed
|
47
|
+
@seed ||= (rand * 100_000).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def buckets
|
51
|
+
@buckets ||= {}.tap do |buckets|
|
52
|
+
Find.find(spec_root) do |path|
|
53
|
+
next unless File.file?(path)
|
54
|
+
next unless path =~ /_spec\.rb\z/
|
55
|
+
rel_path = path[(spec_root.length + 1)..path.length]
|
56
|
+
|
57
|
+
found = false
|
58
|
+
classifiers.each do |(regexp, category)|
|
59
|
+
if regexp =~ rel_path
|
60
|
+
buckets[category] ||= []
|
61
|
+
buckets[category] << File.join('spec', rel_path)
|
62
|
+
found = true
|
63
|
+
break
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
unless found
|
68
|
+
buckets[nil] ||= []
|
69
|
+
buckets[nil] << File.join('spec', rel_path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end.freeze
|
73
|
+
end
|
74
|
+
|
75
|
+
def ordered_buckets
|
76
|
+
@ordered_buckets ||= {}.tap do |ordered_buckets|
|
77
|
+
buckets = self.buckets.dup
|
78
|
+
priority_order.each do |category|
|
79
|
+
files = buckets.delete(category)
|
80
|
+
ordered_buckets[category] = files
|
81
|
+
end
|
82
|
+
|
83
|
+
if files = buckets.delete(nil)
|
84
|
+
ordered_buckets[nil] = files
|
85
|
+
end
|
86
|
+
|
87
|
+
unless buckets.empty?
|
88
|
+
raise BucketsNotPrioritized, "Some buckets were not prioritized: #{buckets.keys.map(&:to_s).join(', ')}"
|
89
|
+
end
|
90
|
+
end.freeze
|
91
|
+
end
|
92
|
+
|
93
|
+
def run
|
94
|
+
run_buckets(*buckets.keys)
|
95
|
+
end
|
96
|
+
|
97
|
+
def run_buckets(*buckets)
|
98
|
+
FileUtils.rm_f(rspec_all_json_path)
|
99
|
+
|
100
|
+
buckets.each do |bucket|
|
101
|
+
if bucket && !self.buckets[bucket]
|
102
|
+
raise "Unknown bucket #{bucket}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
buckets = Hash[self.buckets.select { |k, v| buckets.include?(k) }]
|
106
|
+
|
107
|
+
failed = []
|
108
|
+
|
109
|
+
priority_order.each do |category|
|
110
|
+
if files = buckets.delete(category)
|
111
|
+
unless run_files(category, files)
|
112
|
+
failed << category
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if files = buckets.delete(nil)
|
117
|
+
unless run_files('remaining', files)
|
118
|
+
failed << 'remaining'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
unless buckets.empty?
|
123
|
+
raise "Some buckets were not executed: #{buckets.keys.map(&:to_s).join(', ')}"
|
124
|
+
end
|
125
|
+
|
126
|
+
if failed.any?
|
127
|
+
raise "The following buckets failed: #{failed.map(&:to_s).join(', ')}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def run_files(category, paths)
|
132
|
+
puts "Running #{category.to_s.gsub('_', ' ')} tests"
|
133
|
+
FileUtils.rm_f(rspec_json_path)
|
134
|
+
cmd = %w(rspec) + paths
|
135
|
+
if randomize?
|
136
|
+
cmd += %W(--order rand:#{seed})
|
137
|
+
end
|
138
|
+
|
139
|
+
begin
|
140
|
+
puts "Running #{cmd.join(' ')}"
|
141
|
+
ChildProcessHelper.check_call(cmd)
|
142
|
+
ensure
|
143
|
+
if File.exist?(rspec_json_path)
|
144
|
+
if File.exist?(rspec_all_json_path)
|
145
|
+
merge_rspec_results
|
146
|
+
else
|
147
|
+
FileUtils.cp(rspec_json_path, rspec_all_json_path)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
true
|
153
|
+
rescue ChildProcessHelper::SpawnError
|
154
|
+
false
|
155
|
+
end
|
156
|
+
|
157
|
+
def merge_rspec_results
|
158
|
+
all = JSON.parse(File.read(rspec_all_json_path))
|
159
|
+
new = JSON.parse(File.read(rspec_json_path))
|
160
|
+
all['examples'] += new.delete('examples')
|
161
|
+
new.delete('summary').each do |k, v|
|
162
|
+
all['summary'][k] += v
|
163
|
+
end
|
164
|
+
new.delete('version')
|
165
|
+
new.delete('summary_line')
|
166
|
+
# The spec organizer runs all buckets with the same seed, hence
|
167
|
+
# we can drop the seed from new results.
|
168
|
+
new.delete('seed')
|
169
|
+
unless new.empty?
|
170
|
+
raise "Unhandled rspec results keys: #{new.keys.join(', ')}"
|
171
|
+
end
|
172
|
+
# We do not merge summary lines, delete them from aggregated results
|
173
|
+
all.delete('summary_line')
|
174
|
+
File.open(rspec_all_json_path, 'w') do |f|
|
175
|
+
f << JSON.dump(all)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|