Skip to content

Commit

Permalink
Merge branch 'master' into GODRIVER-2348
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Feb 1, 2024
2 parents 54abbc5 + d844e17 commit a4c7211
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
35 changes: 21 additions & 14 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,16 @@ axes:
variables:
GO_DIST: "/opt/golang/go1.20"

- id: serverless-type
display_name: "Serverless Type"
values:
- id: "original"
display_name: "Serverless"
- id: "proxy"
display_name: "Serverless Proxy"
variables:
VAULT_NAME: "serverless_next"

task_groups:
- name: serverless_task_group
setup_group_can_fail_task: true
Expand All @@ -2298,12 +2308,8 @@ task_groups:
shell: "bash"
script: |
${PREPARE_SHELL}
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
LOADBALANCED=ON \
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
bash ${DRIVERS_TOOLS}/.evergreen/serverless/setup-secrets.sh ${VAULT_NAME}
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
- command: expansions.update
params:
file: serverless-expansion.yml
Expand Down Expand Up @@ -2339,12 +2345,7 @@ task_groups:
shell: "bash"
script: |
${PREPARE_SHELL}
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
- func: handle-test-artifacts
- func: cleanup
tasks:
Expand Down Expand Up @@ -2667,8 +2668,14 @@ buildvariants:

- matrix_name: "serverless"
tags: ["pullrequest"]
matrix_spec: { os-serverless: "*" }
display_name: "Serverless ${os-serverless}"
matrix_spec: { os-serverless: "*", serverless-type: "original" }
display_name: "${serverless-type} ${os-serverless}"
tasks:
- "serverless_task_group"

- matrix_name: "serverless-proxy"
matrix_spec: { os-serverless: "*", serverless-type: "proxy" }
display_name: "${serverless-type} ${os-serverless}"
tasks:
- "serverless_task_group"

Expand Down
10 changes: 9 additions & 1 deletion internal/integration/client_side_encryption_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,15 @@ func TestClientSideEncryptionProse(t *testing.T) {
crypt, err := mongocrypt.NewMongoCrypt(opts)
assert.Nil(mt, err, "error in NewMongoCrypt: %v", err)
_, err = crypt.GetKmsProviders(context.Background())
assert.ErrorContains(mt, err, "Client.Timeout or context cancellation while reading body")

possibleErrors := []string{
"error reading response body: context deadline exceeded", // <= 1.19 + RHEL & macOS
"Client.Timeout or context cancellation while reading body", // > 1.20 on all OS
}

assert.True(t, containsSubstring(possibleErrors, err.Error()),
"expected possibleErrors=%v to contain %v, but it didn't",
possibleErrors, err.Error())
})
})

Expand Down
21 changes: 21 additions & 0 deletions mongo/description/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,27 @@ func BenchmarkSelector_Sharded(b *testing.B) {
}
}

func Benchmark_SelectServer_SelectServer(b *testing.B) {
topology := Topology{Kind: ReplicaSet} // You can change the topology as needed
candidates := []Server{
{Kind: Mongos},
{Kind: RSPrimary},
{Kind: Standalone},
}

selector := writeServerSelector{} // Assuming this is the receiver type

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := selector.SelectServer(topology, candidates)
if err != nil {
b.Fatalf("Error selecting server: %v", err)
}
}
}

func TestSelector_Single(t *testing.T) {
t.Parallel()

Expand Down
12 changes: 11 additions & 1 deletion mongo/description/server_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,17 @@ func (writeServerSelector) SelectServer(t Topology, candidates []Server) ([]Serv
case Single, LoadBalanced:
return candidates, nil
default:
result := []Server{}
// Determine the capacity of the results slice.
selected := 0
for _, candidate := range candidates {
switch candidate.Kind {
case Mongos, RSPrimary, Standalone:
selected++
}
}

// Append candidates to the results slice.
result := make([]Server, 0, selected)
for _, candidate := range candidates {
switch candidate.Kind {
case Mongos, RSPrimary, Standalone:
Expand Down

0 comments on commit a4c7211

Please sign in to comment.