Skip to content

Commit

Permalink
GODRIVER-2292 Support dedicated load balancer port in tests. (mongodb…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale authored and Mohammad Fahim Abrar committed Mar 17, 2022
1 parent e1d2ff8 commit 2b2240c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
12 changes: 11 additions & 1 deletion .evergreen/config.yml
Expand Up @@ -189,6 +189,7 @@ functions:
SSL=${SSL} \
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
LOAD_BALANCER=${LOAD_BALANCER} \
sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
- command: expansions.update
params:
Expand Down Expand Up @@ -1446,6 +1447,7 @@ tasks:
TOPOLOGY: "sharded_cluster"
AUTH: "noauth"
SSL: "nossl"
LOAD_BALANCER: "true"
- func: run-load-balancer
- func: run-load-balancer-tests

Expand All @@ -1457,6 +1459,7 @@ tasks:
TOPOLOGY: "sharded_cluster"
AUTH: "auth"
SSL: "ssl"
LOAD_BALANCER: "true"
- func: run-load-balancer
- func: run-load-balancer-tests

Expand Down Expand Up @@ -1855,6 +1858,10 @@ axes:
display_name: "2.6"
variables:
VERSION: "2.6"
- id: "rapid"
display_name: "rapid"
variables:
VERSION: "rapid"
- id: "latest"
display_name: "latest"
variables:
Expand Down Expand Up @@ -2155,7 +2162,10 @@ buildvariants:

- matrix_name: "load-balancer-test"
# The LB software is only available on Ubuntu 18.04, so we don't test on all OSes.
matrix_spec: { version: ["5.0", "latest"], os-ssl-40: ["ubuntu1804-64-go-1-16"] }
# The new "loadBalancerPort" option is supported starting with server 5.2, which responds
# correctly to "hello" commands with a service ID when behind a load balancer. Only run load
# balancer tests on server 5.2+ ("rapid", "latest" are always 5.2+).
matrix_spec: { version: ["rapid", "latest"], os-ssl-40: ["ubuntu1804-64-go-1-16"] }
display_name: "Load Balancer Support ${version} ${os-ssl-40}"
tasks:
- name: ".load-balancer"
Expand Down
5 changes: 0 additions & 5 deletions internal/const.go
Expand Up @@ -9,11 +9,6 @@ package internal // import "go.mongodb.org/mongo-driver/internal"
// Version is the current version of the driver.
var Version = "local build"

// SetMockServiceID enables a mode in which the driver mocks server support for returning a "serviceId" field in "hello"
// command responses by using the value of "topologyVersion.processId". This is used for testing load balancer support
// until an upstream service can support running behind a load balancer.
var SetMockServiceID = false

// LegacyHello is the legacy version of the hello command.
var LegacyHello = "isMaster"

Expand Down
4 changes: 0 additions & 4 deletions mongo/description/server.go
Expand Up @@ -286,10 +286,6 @@ func NewServer(addr address.Address, response bson.Raw) Server {
desc.LastError = err
return desc
}

if internal.SetMockServiceID {
desc.ServiceID = &desc.TopologyVersion.ProcessID
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion mongo/integration/initial_dns_seedlist_discovery_test.go
Expand Up @@ -76,6 +76,15 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
mt.Skip("skipping to avoid go1.11 problem with multiple strings in one TXT record")
}

// TODO(GODRIVER-2312): Unskip these tests when the DNS SRV records are updated to point to the
// load balancer instead of directly to the mongos.
if strings.HasSuffix(file, "load-balanced/loadBalanced-directConnection.json") ||
strings.HasSuffix(file, "load-balanced/loadBalanced-true-txt.json") ||
strings.HasSuffix(file, "load-balanced/srvMaxHosts-zero-txt.json") ||
strings.HasSuffix(file, "load-balanced/srvMaxHosts-zero.json") {
mt.Skip("skipping because the DNS SRV records need to be updated to work correctly (GODRIVER-2312)")
}

cs, err := connstring.ParseAndValidate(test.URI)
if test.Error {
assert.NotNil(mt, err, "expected URI parsing error, got nil")
Expand Down Expand Up @@ -116,7 +125,7 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
}
for _, host := range test.Hosts {
_, err := getServerByAddress(host, topo)
assert.Nil(mt, err, "did not find host %v", host)
assert.Nil(mt, err, "error finding host %q: %v", host, err)
}
}

Expand Down
10 changes: 0 additions & 10 deletions mongo/integration/main_test.go
Expand Up @@ -9,22 +9,12 @@ package integration
import (
"log"
"os"
"strings"
"testing"

"go.mongodb.org/mongo-driver/internal"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
)

func TestMain(m *testing.M) {
// If the cluster is behind a load balancer, enable the SetMockServiceID flag to mock server-side LB support.
if strings.Contains(os.Getenv("MONGODB_URI"), "loadBalanced=true") {
internal.SetMockServiceID = true
defer func() {
internal.SetMockServiceID = false
}()
}

if err := mtest.Setup(); err != nil {
log.Fatal(err)
}
Expand Down
10 changes: 0 additions & 10 deletions mongo/integration/unified/main_test.go
Expand Up @@ -9,22 +9,12 @@ package unified
import (
"log"
"os"
"strings"
"testing"

"go.mongodb.org/mongo-driver/internal"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
)

func TestMain(m *testing.M) {
// If the cluster is behind a load balancer, enable the SetMockServiceID flag to mock server-side LB support.
if strings.Contains(os.Getenv("MONGODB_URI"), "loadBalanced=true") {
internal.SetMockServiceID = true
defer func() {
internal.SetMockServiceID = false
}()
}

if err := mtest.Setup(); err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 2b2240c

Please sign in to comment.