Skip to content

Commit 1eb7c89

Browse files
committed
Merge branch 'master' into godriver3289
2 parents 9add837 + b225485 commit 1eb7c89

File tree

151 files changed

+18442
-2662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+18442
-2662
lines changed

.evergreen/config.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,25 @@ functions:
561561
KMS_MOCK_SERVERS_RUNNING: "true"
562562
args: [*task-runner, evg-test-kmip]
563563

564+
run-retry-kms-requests:
565+
- command: subprocess.exec
566+
type: test
567+
params:
568+
binary: "bash"
569+
env:
570+
GO_BUILD_TAGS: cse
571+
include_expansions_in_env: [AUTH, SSL, MONGODB_URI, TOPOLOGY,
572+
MONGO_GO_DRIVER_COMPRESSOR]
573+
args: [*task-runner, setup-test]
574+
- command: subprocess.exec
575+
type: test
576+
params:
577+
binary: "bash"
578+
env:
579+
KMS_FAILPOINT_CA_FILE: "${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"
580+
KMS_FAILPOINT_SERVER_RUNNING: "true"
581+
args: [*task-runner, evg-test-retry-kms-requests]
582+
564583
run-fuzz-tests:
565584
- command: subprocess.exec
566585
type: test
@@ -1468,7 +1487,7 @@ tasks:
14681487
SSL: "nossl"
14691488

14701489
- name: "test-kms-tls-invalid-cert"
1471-
tags: ["kms-tls"]
1490+
tags: ["kms-test"]
14721491
commands:
14731492
- func: bootstrap-mongo-orchestration
14741493
vars:
@@ -1484,7 +1503,7 @@ tasks:
14841503
SSL: "nossl"
14851504

14861505
- name: "test-kms-tls-invalid-hostname"
1487-
tags: ["kms-tls"]
1506+
tags: ["kms-test"]
14881507
commands:
14891508
- func: bootstrap-mongo-orchestration
14901509
vars:
@@ -1514,6 +1533,17 @@ tasks:
15141533
AUTH: "noauth"
15151534
SSL: "nossl"
15161535

1536+
- name: "test-retry-kms-requests"
1537+
tags: ["kms-test"]
1538+
commands:
1539+
- func: bootstrap-mongo-orchestration
1540+
vars:
1541+
TOPOLOGY: "server"
1542+
AUTH: "noauth"
1543+
SSL: "nossl"
1544+
- func: start-cse-servers
1545+
- func: run-retry-kms-requests
1546+
15171547
- name: "test-serverless"
15181548
tags: ["serverless"]
15191549
commands:
@@ -2201,11 +2231,11 @@ buildvariants:
22012231
tasks:
22022232
- name: ".versioned-api"
22032233

2204-
- matrix_name: "kms-tls-test"
2234+
- matrix_name: "kms-test"
22052235
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64"] }
2206-
display_name: "KMS TLS ${os-ssl-40}"
2236+
display_name: "KMS TEST ${os-ssl-40}"
22072237
tasks:
2208-
- name: ".kms-tls"
2238+
- name: ".kms-test"
22092239

22102240
- matrix_name: "load-balancer-test"
22112241
tags: ["pullrequest"]

.github/workflows/merge-up.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Merge up
2+
3+
on:
4+
push:
5+
branches:
6+
- release/*.*
7+
- v*
8+
9+
permissions:
10+
id-token: write
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
merge-up:
16+
name: Create merge up pull request
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
21+
with:
22+
app_id: ${{ vars.PR_APP_ID }}
23+
private_key: ${{ secrets.PR_APP_PRIVATE_KEY }}
24+
# Make sure to include fetch-depth 0 so all branches are fetched, not
25+
# just the current one
26+
fetch-depth: 0
27+
28+
- name: Create pull request
29+
id: create-pull-request
30+
uses: alcaeus/automatic-merge-up-action@main
31+
with:
32+
ref: ${{ github.ref_name }}
33+
branchNamePattern: 'release/<major>.<minor>'
34+
devBranchNamePattern: 'v<major>'
35+
fallbackBranch: 'master'
36+
enableAutoMerge: true

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ tasks:
143143
evg-test-kms:
144144
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionProse/kms_tls_tests >> test.suite
145145

146+
evg-test-retry-kms-requests:
147+
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionProse/kms_retry_tests >> test.suite
148+
146149
evg-test-load-balancers:
147150
# Load balancer should be tested with all unified tests as well as tests in the following
148151
# components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright (C) MongoDB, Inc. 2024-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package bson
8+
9+
import (
10+
"encoding/hex"
11+
"encoding/json"
12+
"math"
13+
"os"
14+
"path"
15+
"testing"
16+
17+
"go.mongodb.org/mongo-driver/v2/internal/require"
18+
)
19+
20+
const bsonBinaryVectorDir = "../testdata/bson-binary-vector/"
21+
22+
type bsonBinaryVectorTests struct {
23+
Description string `json:"description"`
24+
TestKey string `json:"test_key"`
25+
Tests []bsonBinaryVectorTestCase `json:"tests"`
26+
}
27+
28+
type bsonBinaryVectorTestCase struct {
29+
Description string `json:"description"`
30+
Valid bool `json:"valid"`
31+
Vector []interface{} `json:"vector"`
32+
DtypeHex string `json:"dtype_hex"`
33+
DtypeAlias string `json:"dtype_alias"`
34+
Padding int `json:"padding"`
35+
CanonicalBson string `json:"canonical_bson"`
36+
}
37+
38+
func TestBsonBinaryVectorSpec(t *testing.T) {
39+
t.Parallel()
40+
41+
jsonFiles, err := findJSONFilesInDir(bsonBinaryVectorDir)
42+
require.NoErrorf(t, err, "error finding JSON files in %s: %v", bsonBinaryVectorDir, err)
43+
44+
for _, file := range jsonFiles {
45+
filepath := path.Join(bsonBinaryVectorDir, file)
46+
content, err := os.ReadFile(filepath)
47+
require.NoErrorf(t, err, "reading test file %s", filepath)
48+
49+
var tests bsonBinaryVectorTests
50+
require.NoErrorf(t, json.Unmarshal(content, &tests), "parsing test file %s", filepath)
51+
52+
t.Run(tests.Description, func(t *testing.T) {
53+
t.Parallel()
54+
55+
for _, test := range tests.Tests {
56+
test := test
57+
t.Run(test.Description, func(t *testing.T) {
58+
t.Parallel()
59+
60+
runBsonBinaryVectorTest(t, tests.TestKey, test)
61+
})
62+
}
63+
})
64+
}
65+
66+
t.Run("Padding specified with no vector data PACKED_BIT", func(t *testing.T) {
67+
t.Parallel()
68+
69+
t.Run("Marshaling", func(t *testing.T) {
70+
_, err := NewPackedBitVector(nil, 1)
71+
require.EqualError(t, err, errNonZeroVectorPadding.Error())
72+
})
73+
})
74+
75+
t.Run("Exceeding maximum padding PACKED_BIT", func(t *testing.T) {
76+
t.Parallel()
77+
78+
t.Run("Marshaling", func(t *testing.T) {
79+
_, err := NewPackedBitVector(nil, 8)
80+
require.EqualError(t, err, errVectorPaddingTooLarge.Error())
81+
})
82+
})
83+
}
84+
85+
func convertSlice[T int8 | float32 | byte](s []interface{}) []T {
86+
v := make([]T, len(s))
87+
for i, e := range s {
88+
f := math.NaN()
89+
switch val := e.(type) {
90+
case float64:
91+
f = val
92+
case string:
93+
if val == "inf" {
94+
f = math.Inf(0)
95+
} else if val == "-inf" {
96+
f = math.Inf(-1)
97+
}
98+
}
99+
v[i] = T(f)
100+
}
101+
return v
102+
}
103+
104+
func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVectorTestCase) {
105+
testVector := make(map[string]Vector)
106+
switch alias := test.DtypeHex; alias {
107+
case "0x03":
108+
testVector[testKey] = Vector{
109+
dType: Int8Vector,
110+
int8Data: convertSlice[int8](test.Vector),
111+
}
112+
case "0x27":
113+
testVector[testKey] = Vector{
114+
dType: Float32Vector,
115+
float32Data: convertSlice[float32](test.Vector),
116+
}
117+
case "0x10":
118+
testVector[testKey] = Vector{
119+
dType: PackedBitVector,
120+
bitData: convertSlice[byte](test.Vector),
121+
bitPadding: uint8(test.Padding),
122+
}
123+
default:
124+
t.Fatalf("unsupported vector type: %s", alias)
125+
}
126+
127+
testBSON, err := hex.DecodeString(test.CanonicalBson)
128+
require.NoError(t, err, "decoding canonical BSON")
129+
130+
t.Run("Unmarshaling", func(t *testing.T) {
131+
skipCases := map[string]string{
132+
"Overflow Vector INT8": "compile-time restriction",
133+
"Underflow Vector INT8": "compile-time restriction",
134+
"INT8 with float inputs": "compile-time restriction",
135+
"Overflow Vector PACKED_BIT": "compile-time restriction",
136+
"Underflow Vector PACKED_BIT": "compile-time restriction",
137+
"Vector with float values PACKED_BIT": "compile-time restriction",
138+
"Negative padding PACKED_BIT": "compile-time restriction",
139+
}
140+
if reason, ok := skipCases[test.Description]; ok {
141+
t.Skipf("skip test case %s: %s", test.Description, reason)
142+
}
143+
144+
errMap := map[string]string{
145+
"FLOAT32 with padding": "padding must be 0",
146+
"INT8 with padding": "padding must be 0",
147+
"Padding specified with no vector data PACKED_BIT": "padding must be 0",
148+
"Exceeding maximum padding PACKED_BIT": "padding cannot be larger than 7",
149+
}
150+
151+
t.Parallel()
152+
153+
var got map[string]Vector
154+
err := Unmarshal(testBSON, &got)
155+
if test.Valid {
156+
require.NoError(t, err)
157+
require.Equal(t, testVector, got)
158+
} else if errMsg, ok := errMap[test.Description]; ok {
159+
require.ErrorContains(t, err, errMsg)
160+
} else {
161+
require.Error(t, err)
162+
}
163+
})
164+
165+
t.Run("Marshaling", func(t *testing.T) {
166+
skipCases := map[string]string{
167+
"FLOAT32 with padding": "private padding field",
168+
"Insufficient vector data with 3 bytes FLOAT32": "invalid case",
169+
"Insufficient vector data with 5 bytes FLOAT32": "invalid case",
170+
"Overflow Vector INT8": "compile-time restriction",
171+
"Underflow Vector INT8": "compile-time restriction",
172+
"INT8 with padding": "private padding field",
173+
"INT8 with float inputs": "compile-time restriction",
174+
"Overflow Vector PACKED_BIT": "compile-time restriction",
175+
"Underflow Vector PACKED_BIT": "compile-time restriction",
176+
"Vector with float values PACKED_BIT": "compile-time restriction",
177+
"Padding specified with no vector data PACKED_BIT": "run in alternative case",
178+
"Exceeding maximum padding PACKED_BIT": "run in alternative case",
179+
"Negative padding PACKED_BIT": "compile-time restriction",
180+
}
181+
if reason, ok := skipCases[test.Description]; ok {
182+
t.Skipf("skip test case %s: %s", test.Description, reason)
183+
}
184+
185+
t.Parallel()
186+
187+
got, err := Marshal(testVector)
188+
require.NoError(t, err)
189+
require.Equal(t, testBSON, got)
190+
})
191+
}

0 commit comments

Comments
 (0)