| 1 |
From: Shengjing Zhu <[email protected]> |
| 2 |
Date: Fri, 10 Nov 2023 16:39:44 +0800 |
| 3 |
Subject: Skip tests which need networking |
| 4 |
|
| 5 |
We should not be performing external network accesses when running the |
| 6 |
tests, as the CI and build daemons might not permit such access. |
| 7 |
|
| 8 |
Co-Author: Guillem Jover <[email protected]> |
| 9 |
--- |
| 10 |
mongo/options/clientoptions_test.go | 5 +++++ |
| 11 |
x/mongo/driver/connstring/connstring_spec_test.go | 3 +++ |
| 12 |
x/mongo/driver/topology/polling_srv_records_test.go | 2 ++ |
| 13 |
x/mongo/driver/topology/server_test.go | 3 +++ |
| 14 |
x/mongo/driver/topology/topology_test.go | 4 ++++ |
| 15 |
5 files changed, 17 insertions(+) |
| 16 |
|
| 17 |
diff --git a/mongo/options/clientoptions_test.go b/mongo/options/clientoptions_test.go |
| 18 |
index f85a112..6c01ef2 100644 |
| 19 |
--- a/mongo/options/clientoptions_test.go |
| 20 |
+++ b/mongo/options/clientoptions_test.go |
| 21 |
@@ -21,6 +21,7 @@ import ( |
| 22 |
"reflect" |
| 23 |
"testing" |
| 24 |
"time" |
| 25 |
+ "strings" |
| 26 |
|
| 27 |
"github.com/google/go-cmp/cmp" |
| 28 |
"github.com/google/go-cmp/cmp/cmpopts" |
| 29 |
@@ -626,6 +627,10 @@ func TestClientOptions(t *testing.T) { |
| 30 |
|
| 31 |
for _, tc := range testCases { |
| 32 |
t.Run(tc.name, func(t *testing.T) { |
| 33 |
+ if strings.HasPrefix(tc.name, "srv") && testing.Short() { |
| 34 |
+ t.Skip("Skipping test due to network access for DNS SRV resolution") |
| 35 |
+ } |
| 36 |
+ |
| 37 |
result := Client().ApplyURI(tc.uri) |
| 38 |
|
| 39 |
// Manually add the URI and ConnString to the test expectations to avoid adding them in each test |
| 40 |
diff --git a/x/mongo/driver/connstring/connstring_spec_test.go b/x/mongo/driver/connstring/connstring_spec_test.go |
| 41 |
index aea68eb..262799f 100644 |
| 42 |
--- a/x/mongo/driver/connstring/connstring_spec_test.go |
| 43 |
+++ b/x/mongo/driver/connstring/connstring_spec_test.go |
| 44 |
@@ -110,6 +110,9 @@ var skipKeywords = []string{ |
| 45 |
|
| 46 |
func runTest(t *testing.T, filename string, test testCase, warningsError bool) { |
| 47 |
t.Run(filename+"/"+test.Description, func(t *testing.T) { |
| 48 |
+ if filename == "srv-options" && testing.Short() { |
| 49 |
+ t.Skip("Skipping test due to network access for DNS SRV resolution") |
| 50 |
+ } |
| 51 |
if _, skip := skipDescriptions[test.Description]; skip { |
| 52 |
t.Skip() |
| 53 |
} |
| 54 |
diff --git a/x/mongo/driver/topology/polling_srv_records_test.go b/x/mongo/driver/topology/polling_srv_records_test.go |
| 55 |
index 04f5e8c..569f221 100644 |
| 56 |
--- a/x/mongo/driver/topology/polling_srv_records_test.go |
| 57 |
+++ b/x/mongo/driver/topology/polling_srv_records_test.go |
| 58 |
@@ -4,6 +4,8 @@ |
| 59 |
// not use this file except in compliance with the License. You may obtain |
| 60 |
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 61 |
|
| 62 |
+//go:build ignore |
| 63 |
+ |
| 64 |
package topology |
| 65 |
|
| 66 |
import ( |
| 67 |
diff --git a/x/mongo/driver/topology/server_test.go b/x/mongo/driver/topology/server_test.go |
| 68 |
index 1c10d61..03d06f7 100644 |
| 69 |
--- a/x/mongo/driver/topology/server_test.go |
| 70 |
+++ b/x/mongo/driver/topology/server_test.go |
| 71 |
@@ -131,6 +131,9 @@ func TestServerHeartbeatTimeout(t *testing.T) { |
| 72 |
if os.Getenv("DOCKER_RUNNING") != "" { |
| 73 |
t.Skip("Skipping this test in docker.") |
| 74 |
} |
| 75 |
+ if testing.Short() { |
| 76 |
+ t.Skip("Skipping test that needs MongoDB server.") |
| 77 |
+ } |
| 78 |
|
| 79 |
networkTimeoutError := &net.DNSError{ |
| 80 |
IsTimeout: true, |
| 81 |
diff --git a/x/mongo/driver/topology/topology_test.go b/x/mongo/driver/topology/topology_test.go |
| 82 |
index ad91d95..68c4d32 100644 |
| 83 |
--- a/x/mongo/driver/topology/topology_test.go |
| 84 |
+++ b/x/mongo/driver/topology/topology_test.go |
| 85 |
@@ -915,6 +915,10 @@ func TestTopologyConstructionLogging(t *testing.T) { |
| 86 |
t.Run(tc.name, func(t *testing.T) { |
| 87 |
t.Parallel() |
| 88 |
|
| 89 |
+ if tc.name == "srv" && testing.Short() { |
| 90 |
+ t.Skip("Skipping test due to network access for DNS SRV resolution") |
| 91 |
+ } |
| 92 |
+ |
| 93 |
sink := &mockLogSink{} |
| 94 |
cfg, err := NewConfig(options.Client().ApplyURI(tc.uri).SetLoggerOptions(newLoggerOptions(sink)), nil) |
| 95 |
require.Nil(t, err, "error constructing topology config: %v", err) |