diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 2bdb6ce8ac..a81f00e35a 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -27,7 +27,7 @@ timeout: ls -la functions: fetch-source: - # Executes git clone and applies the submitted patch, if any + # Executes clone and applies the submitted patch, if any - command: git.get_project type: system params: @@ -1522,8 +1522,8 @@ tasks: - func: run-atlas-data-lake-test - name: test-docker-runner - tags: ["pullrequest"] commands: + - func: bootstrap-mongo-orchestration - func: run-docker-test - name: test-load-balancer-noauth-nossl @@ -2579,6 +2579,7 @@ buildvariants: - name: "test-atlas-data-lake" - name: docker-runner-test + tags: ["pullrequest"] display_name: "Docker Runner Test" run_on: - ubuntu2204-large diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 12e22a0d62..efabc1bfac 100644 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -18,7 +18,6 @@ fi export GOROOT="${GOROOT}" export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH" -export PATH="${MONGODB_BINARIES:-$DRIVERS_TOOLS/mongodb/bin}:$PATH" export PROJECT="${project}" export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64 diff --git a/Dockerfile b/Dockerfile index d49c7ca1a7..cd56254a5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,15 +16,19 @@ COPY etc/install-libmongocrypt.sh /root/install-libmongocrypt.sh RUN cd /root && bash ./install-libmongocrypt.sh -# Inherit from the drivers-evergreen-tools image and copy in the files -# from the libmongocrypt build stage. -FROM drivers-evergreen-tools +# Copy in the files from the libmongocrypt build stage. +FROM ubuntu:20.04 # Install common deps. RUN export DEBIAN_FRONTEND=noninteractive && \ export TZ=Etc/UTC && \ apt-get -qq update && \ apt-get -qqy install --reinstall --no-install-recommends \ + git \ + ca-certificates \ + curl \ + wget \ + sudo \ tzdata \ ca-certificates \ pkg-config \ @@ -50,4 +54,6 @@ COPY ./etc/docker_entry.sh /root/docker_entry.sh COPY --from=libmongocrypt /root/install /root/install +ENV DOCKER_RUNNING=true + ENTRYPOINT ["/bin/bash", "/root/docker_entry.sh"] diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 72820c93d4..95dbf3e0f0 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -154,19 +154,56 @@ The usage of host.docker.internal comes from the [Docker networking documentatio There is currently no arm64 support for the go1.x runtime, see [here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). Known issues running on linux/arm64 include the inability to network with the localhost from the public.ecr.aws/lambda/go Docker image. +### Load Balancer + +To launch the load balancer on MacOS, run the following. + +- `brew install haproxy` +- Clone drivers-evergreen-tools and save the path as `DRIVERS_TOOLS`. +- Start the servers using (or use the docker-based method below): + +```bash +LOAD_BALANCER=true TOPOLOGY=sharded_cluster AUTH=noauth SSL=nossl MONGODB_VERSION=6.0 DRIVERS_TOOLS=$PWD/drivers-evergreen-tools MONGO_ORCHESTRATION_HOME=$PWD/drivers-evergreen-tools/.evergreen/orchestration $PWD/drivers-evergreen-tools/.evergreen/run-orchestration.sh +``` + +- Start the load balancer using: + +```bash +MONGODB_URI='mongodb://localhost:27017,localhost:27018/' $PWD/drivers-evergreen-tools/.evergreen/run-load-balancer.sh start +``` + +- Run the load balancer tests (or use the docker runner below with `evg-test-load-balancers`): + +```bash +make evg-test-load-balancers +``` + ### Testing in Docker We support local testing in Docker. To test using docker, you will need to set the `DRIVERS_TOOLs` environment variable to point to a local clone of the drivers-evergreen-tools repository. This is essential for running the testing matrix in a container. You can set the `DRIVERS_TOOLS` variable in your shell profile or in your project-specific environment. +1. First, start the drivers-tools server docker container, as: + +```bash +bash $DRIVERS_TOOLS/.evergreen/docker/start-server.sh +``` + +See the readme in `$DRIVERS_TOOLS/.evergreen/docker` for more information on usage. + +2. Next, start any other required services in another terminal, like a load balancer. + +1. Finally, run the Go Driver tests using the following script in this repo: + ```bash bash etc/run_docker.sh ``` The script takes an optional argument for the `MAKEFILE_TARGET` and allows for some environment variable overrides. The docker container has the required binaries, including libmongocrypt. -The entry script starts a MongoDB topology, and then executes the desired `MAKEFILE_TARGET`. +The entry script executes the desired `MAKEFILE_TARGET`. -For example, to test against a sharded cluster, using enterprise auth, run: +For example, to test against a sharded cluster (make sure you started the server with a sharded_cluster), +using enterprise auth, run: ```bash TOPOLOGY=sharded_cluster bash etc/run_docker.sh evg-test-enterprise-auth diff --git a/etc/docker_entry.sh b/etc/docker_entry.sh index 51f31217f1..4e3e325970 100644 --- a/etc/docker_entry.sh +++ b/etc/docker_entry.sh @@ -1,17 +1,14 @@ #!/usr/bin/env bash # -# Entry point for Dockerfile for launching a server and running a go test. +# Entry point for Dockerfile for running a go test. # set -eux -# Start the server. -bash /root/base-entrypoint.sh -source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh - # Prep files. cd /src rm -f test.suite cp -r $HOME/install ./install + export PATH="$MONGODB_BINARIES:$PATH" # Run the test. diff --git a/etc/run_docker.sh b/etc/run_docker.sh index a4b400035b..b6d0fc9ae5 100644 --- a/etc/run_docker.sh +++ b/etc/run_docker.sh @@ -8,33 +8,17 @@ if [ -z "$DRIVERS_TOOLS" ]; then exit 1 fi PLATFORM=${DOCKER_PLATFORM:-} - -pushd $DRIVERS_TOOLS/.evergreen/docker/ubuntu20.04 -docker build $PLATFORM -t drivers-evergreen-tools . -popd docker build $PLATFORM -t go-test . # Handle environment variables and optional positional arg for the makefile target. - MAKEFILE_TARGET=${1:-evg-test-versioned-api} -MONGODB_VERSION=${MONGODB_VERSION:-latest} -TOPOLOGY=${TOPOLOGY:-replica_set} -ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json} -AUTH=${AUTH:-""} -SSL=${SSL:=""} GO_BUILD_TAGS=${GO_BUILD_TAGS:-""} -ENV="-e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY" -ENV="$ENV -e MAKEFILE_TARGET=$MAKEFILE_TARGET -e AUTH=$AUTH" -ENV="$ENV -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE -e SSL=$SSL" -ENV="$ENV -e GO_BUILD_TAGS=$GO_BUILD_TAGS" - -VOL="-v `pwd`:/src" -VOL="$VOL -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools" -USE_TTY="" -test -t 1 && USE_TTY="-t" +ARGS=" -e MAKEFILE_TARGET=$MAKEFILE_TARGET" +ARGS="$ARGS -e GO_BUILD_TAGS=$GO_BUILD_TAGS" +ARGS="$ARGS go-test" -docker run $PLATFORM --rm $VOL $ENV -i $USE_TTY go-test +$DRIVERS_TOOLS/.evergreen/docker/run-client.sh $ARGS if [ -f "test.suite" ]; then tail test.suite fi diff --git a/event/monitoring.go b/event/monitoring.go index 41270ef59f..e064ee0e57 100644 --- a/event/monitoring.go +++ b/event/monitoring.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package event // import "go.mongodb.org/mongo-driver/event" +package event import ( "context" diff --git a/internal/benchmark/harness.go b/internal/benchmark/harness.go index 0c93879a86..4d0940bffc 100644 --- a/internal/benchmark/harness.go +++ b/internal/benchmark/harness.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package benchmark // import "go.mongodb.org/mongo-driver/benchmark" +package benchmark import ( "context" diff --git a/internal/integration/mtest/opmsg_deployment.go b/internal/integration/mtest/opmsg_deployment.go index 04481ebd56..23b258354a 100644 --- a/internal/integration/mtest/opmsg_deployment.go +++ b/internal/integration/mtest/opmsg_deployment.go @@ -21,7 +21,7 @@ import ( ) const ( - serverAddress = address.Address("localhost:27017") + serverAddress = address.Address("127.0.0.1:27017") maxDocumentSize uint32 = 16777216 maxMessageSize uint32 = 48000000 maxBatchCount uint32 = 100000 diff --git a/mongo/address/addr.go b/mongo/address/addr.go index 85cf12067c..e740ad9c8f 100644 --- a/mongo/address/addr.go +++ b/mongo/address/addr.go @@ -5,7 +5,7 @@ // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Package address provides structured representations of network addresses. -package address // import "go.mongodb.org/mongo-driver/mongo/address" +package address import ( "net" diff --git a/mongo/client_test.go b/mongo/client_test.go index 6046b5abc2..ddba3062fe 100644 --- a/mongo/client_test.go +++ b/mongo/client_test.go @@ -337,6 +337,9 @@ func TestClient(t *testing.T) { if testing.Short() { t.Skip("skipping integration test in short mode") } + if os.Getenv("DOCKER_RUNNING") != "" { + t.Skip("skipping test in docker environment") + } t.Run(tc.name, func(t *testing.T) { // Setup a client and skip the test based on server version. diff --git a/mongo/description/description.go b/mongo/description/description.go index e750e33b14..68b61a6249 100644 --- a/mongo/description/description.go +++ b/mongo/description/description.go @@ -5,7 +5,7 @@ // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Package description contains types and functions for describing the state of MongoDB clusters. -package description // import "go.mongodb.org/mongo-driver/mongo/description" +package description // Unknown is an unknown server or topology kind. const Unknown = 0 diff --git a/mongo/gridfs/bucket.go b/mongo/gridfs/bucket.go index 5c2a5e3e29..c053132c38 100644 --- a/mongo/gridfs/bucket.go +++ b/mongo/gridfs/bucket.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package gridfs // import "go.mongodb.org/mongo-driver/mongo/gridfs" +package gridfs import ( "bytes" diff --git a/mongo/mongo.go b/mongo/mongo.go index d0e321f7bf..43a22b7229 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package mongo // import "go.mongodb.org/mongo-driver/mongo" +package mongo import ( "bytes" diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index 508a2e4601..9677ef75b0 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package options // import "go.mongodb.org/mongo-driver/mongo/options" +package options import ( "bytes" diff --git a/mongo/readconcern/readconcern.go b/mongo/readconcern/readconcern.go index 8b387c3fd8..398d843012 100644 --- a/mongo/readconcern/readconcern.go +++ b/mongo/readconcern/readconcern.go @@ -8,7 +8,7 @@ // // For more information about MongoDB read concerns, see // https://www.mongodb.com/docs/manual/reference/read-concern/ -package readconcern // import "go.mongodb.org/mongo-driver/mongo/readconcern" +package readconcern import ( "errors" diff --git a/mongo/readpref/readpref.go b/mongo/readpref/readpref.go index e2a1d7f340..40c6ca76da 100644 --- a/mongo/readpref/readpref.go +++ b/mongo/readpref/readpref.go @@ -5,7 +5,7 @@ // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Package readpref defines read preferences for MongoDB queries. -package readpref // import "go.mongodb.org/mongo-driver/mongo/readpref" +package readpref import ( "bytes" diff --git a/mongo/with_transactions_test.go b/mongo/with_transactions_test.go index 24fa280e6f..f65ba7b4f1 100644 --- a/mongo/with_transactions_test.go +++ b/mongo/with_transactions_test.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "math" + "os" "strconv" "strings" "testing" @@ -37,6 +38,9 @@ func TestConvenientTransactions(t *testing.T) { if testing.Short() { t.Skip("skipping integration test in short mode") } + if os.Getenv("DOCKER_RUNNING") != "" { + t.Skip("skipping test in docker environment") + } client := setupConvenientTransactions(t) db := client.Database("TestConvenientTransactions") diff --git a/mongo/writeconcern/writeconcern.go b/mongo/writeconcern/writeconcern.go index 76f8ee16bd..cf1e401284 100644 --- a/mongo/writeconcern/writeconcern.go +++ b/mongo/writeconcern/writeconcern.go @@ -8,7 +8,7 @@ // // For more information about MongoDB write concerns, see // https://www.mongodb.com/docs/manual/reference/write-concern/ -package writeconcern // import "go.mongodb.org/mongo-driver/mongo/writeconcern" +package writeconcern import ( "errors" diff --git a/tag/tag.go b/tag/tag.go index 4faff52549..39c11e0460 100644 --- a/tag/tag.go +++ b/tag/tag.go @@ -8,7 +8,7 @@ // // For more information about read preference tags, see // https://www.mongodb.com/docs/manual/core/read-preference-tags/ -package tag // import "go.mongodb.org/mongo-driver/tag" +package tag import ( "bytes" diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.json b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.json new file mode 100644 index 0000000000..decc83ce10 --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.json @@ -0,0 +1,16 @@ +{ + "uri": "mongodb+srv://TEST1.TEST.BUILD.10GEN.CC", + "seeds": [ + "localhost.test.build.10gen.cc:27017", + "localhost.test.build.10gen.cc:27018" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "ssl": true + }, + "ping": true +} \ No newline at end of file diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.yml b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.yml new file mode 100644 index 0000000000..a0e06c466c --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-uppercase-hostname.yml @@ -0,0 +1,11 @@ +uri: "mongodb+srv://TEST1.TEST.BUILD.10GEN.CC" +seeds: + - localhost.test.build.10gen.cc:27017 + - localhost.test.build.10gen.cc:27018 +hosts: + - localhost:27017 + - localhost:27018 + - localhost:27019 +options: + ssl: true +ping: true \ No newline at end of file diff --git a/version/version.go b/version/version.go index ead90fa049..cf5c00c506 100644 --- a/version/version.go +++ b/version/version.go @@ -5,7 +5,7 @@ // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Package version defines the Go Driver version. -package version // import "go.mongodb.org/mongo-driver/version" +package version // Driver is the current version of the driver. var Driver = "v2.0.0-prerelease" diff --git a/x/bsonx/bsoncore/bsoncore.go b/x/bsonx/bsoncore/bsoncore.go index 88133293ea..2421c8ea76 100644 --- a/x/bsonx/bsoncore/bsoncore.go +++ b/x/bsonx/bsoncore/bsoncore.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package bsoncore // import "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" +package bsoncore import ( "bytes" diff --git a/x/mongo/driver/auth/scram.go b/x/mongo/driver/auth/scram.go index f4f069699c..c1238cd6a9 100644 --- a/x/mongo/driver/auth/scram.go +++ b/x/mongo/driver/auth/scram.go @@ -14,7 +14,6 @@ package auth import ( "context" - "fmt" "github.com/xdg-go/scram" "github.com/xdg-go/stringprep" @@ -53,7 +52,7 @@ func newScramSHA1Authenticator(cred *Cred) (Authenticator, error) { func newScramSHA256Authenticator(cred *Cred) (Authenticator, error) { passprep, err := stringprep.SASLprep.Prepare(cred.Password) if err != nil { - return nil, newAuthError(fmt.Sprintf("error SASLprepping password '%s'", cred.Password), err) + return nil, newAuthError("error SASLprepping password", err) } client, err := scram.SHA256.NewClientUnprepped(cred.Username, passprep, "") if err != nil { diff --git a/x/mongo/driver/connstring/connstring.go b/x/mongo/driver/connstring/connstring.go index b3dc97cf38..6830aa89ae 100644 --- a/x/mongo/driver/connstring/connstring.go +++ b/x/mongo/driver/connstring/connstring.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package connstring // import "go.mongodb.org/mongo-driver/x/mongo/driver/connstring" +package connstring import ( "errors" diff --git a/x/mongo/driver/dns/dns.go b/x/mongo/driver/dns/dns.go index 848554d3a1..6573a4c1ad 100644 --- a/x/mongo/driver/dns/dns.go +++ b/x/mongo/driver/dns/dns.go @@ -104,8 +104,8 @@ func (r *Resolver) fetchSeedlistFromSRV(host string, srvName string, stopOnErr b } func validateSRVResult(recordFromSRV, inputHostName string) error { - separatedInputDomain := strings.Split(inputHostName, ".") - separatedRecord := strings.Split(recordFromSRV, ".") + separatedInputDomain := strings.Split(strings.ToLower(inputHostName), ".") + separatedRecord := strings.Split(strings.ToLower(recordFromSRV), ".") if len(separatedRecord) < 2 { return errors.New("DNS name must contain at least 2 labels") } diff --git a/x/mongo/driver/driver.go b/x/mongo/driver/driver.go index 83eaf99fa6..584bb6012a 100644 --- a/x/mongo/driver/driver.go +++ b/x/mongo/driver/driver.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package driver // import "go.mongodb.org/mongo-driver/x/mongo/driver" +package driver import ( "context" diff --git a/x/mongo/driver/operation/hello_test.go b/x/mongo/driver/operation/hello_test.go index 114f53b617..6bfaf00f6d 100644 --- a/x/mongo/driver/operation/hello_test.go +++ b/x/mongo/driver/operation/hello_test.go @@ -8,6 +8,7 @@ package operation import ( "fmt" + "os" "runtime" "testing" @@ -142,6 +143,10 @@ func TestAppendClientDriver(t *testing.T) { func TestAppendClientEnv(t *testing.T) { clearTestEnv(t) + if os.Getenv("DOCKER_RUNNING") != "" { + t.Skip("These tests gives different results when run in Docker due to extra environment data.") + } + tests := []struct { name string omitEnvFields bool @@ -377,6 +382,10 @@ func TestAppendClientPlatform(t *testing.T) { func TestEncodeClientMetadata(t *testing.T) { clearTestEnv(t) + if os.Getenv("DOCKER_RUNNING") != "" { + t.Skip("These tests gives different results when run in Docker due to extra environment data.") + } + type application struct { Name string `bson:"name"` } diff --git a/x/mongo/driver/session/client_session.go b/x/mongo/driver/session/client_session.go index f48348a687..35c2c3e89d 100644 --- a/x/mongo/driver/session/client_session.go +++ b/x/mongo/driver/session/client_session.go @@ -4,7 +4,7 @@ // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -package session // import "go.mongodb.org/mongo-driver/x/mongo/driver/session" +package session import ( "context" diff --git a/x/mongo/driver/topology/server_test.go b/x/mongo/driver/topology/server_test.go index 84c6481610..12dd0dc03c 100644 --- a/x/mongo/driver/topology/server_test.go +++ b/x/mongo/driver/topology/server_test.go @@ -128,6 +128,10 @@ func (d *timeoutDialer) DialContext(ctx context.Context, network, address string // TestServerHeartbeatTimeout tests timeout retry and preemptive canceling. func TestServerHeartbeatTimeout(t *testing.T) { + if os.Getenv("DOCKER_RUNNING") != "" { + t.Skip("Skipping this test in docker.") + } + networkTimeoutError := &net.DNSError{ IsTimeout: true, } diff --git a/x/mongo/driver/topology/topology.go b/x/mongo/driver/topology/topology.go index ef320b3bfa..1b25ec9721 100644 --- a/x/mongo/driver/topology/topology.go +++ b/x/mongo/driver/topology/topology.go @@ -8,7 +8,7 @@ // of servers. This package is designed to expose enough inner workings of service discovery // and monitoring to allow low level applications to have fine grained control, while hiding // most of the detailed implementation of the algorithms. -package topology // import "go.mongodb.org/mongo-driver/x/mongo/driver/topology" +package topology import ( "context"