Skip to content

Commit 2e04897

Browse files
committed
GODRIVER-3445 Move all logic for skipping spec tests by description into one place.
1 parent e3670f7 commit 2e04897

File tree

8 files changed

+178
-141
lines changed

8 files changed

+178
-141
lines changed

bson/bson_corpus_spec_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,7 @@ func runTest(t *testing.T, file string) {
275275
content, err := os.ReadFile(filepath)
276276
require.NoError(t, err)
277277

278-
// Remove ".json" from filename.
279-
file = file[:len(file)-5]
280-
testName := "bson_corpus--" + file
281-
282-
t.Run(testName, func(t *testing.T) {
278+
t.Run(file, func(t *testing.T) {
283279
var test testCase
284280
require.NoError(t, json.Unmarshal(content, &test))
285281

@@ -429,7 +425,7 @@ func runTest(t *testing.T, file string) {
429425
})
430426
}
431427

432-
func Test_BsonCorpus(t *testing.T) {
428+
func TestBSONCorpus(t *testing.T) {
433429
jsonFiles, err := findJSONFilesInDir(dataDir)
434430
require.NoErrorf(t, err, "error finding JSON files in %s: %v", dataDir, err)
435431

internal/integration/unified_spec_test.go

+5-21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"go.mongodb.org/mongo-driver/v2/internal/failpoint"
2828
"go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2929
"go.mongodb.org/mongo-driver/v2/internal/integtest"
30+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
3031
"go.mongodb.org/mongo-driver/v2/mongo"
3132
"go.mongodb.org/mongo-driver/v2/mongo/address"
3233
"go.mongodb.org/mongo-driver/v2/mongo/options"
@@ -37,26 +38,11 @@ import (
3738
)
3839

3940
const (
40-
gridFSFiles = "fs.files"
41-
gridFSChunks = "fs.chunks"
42-
spec1403SkipReason = "servers less than 4.2 do not have mongocryptd; see SPEC-1403"
43-
godriver2123SkipReason = "failpoints and timeouts together cause failures; see GODRIVER-2123"
41+
gridFSFiles = "fs.files"
42+
gridFSChunks = "fs.chunks"
4443
)
4544

46-
var (
47-
defaultHeartbeatInterval = 500 * time.Millisecond
48-
skippedTestDescriptions = map[string]string{
49-
// SPEC-1403: This test checks to see if the correct error is thrown when auto encrypting with a server < 4.2.
50-
// Currently, the test will fail because a server < 4.2 wouldn't have mongocryptd, so Client construction
51-
// would fail with a mongocryptd spawn error.
52-
"operation fails with maxWireVersion < 8": spec1403SkipReason,
53-
// GODRIVER-2123: The two tests below use a failpoint and a socket or server selection timeout.
54-
// The timeout causes the eventual clearing of the failpoint in the test runner to fail with an
55-
// i/o timeout.
56-
"Ignore network timeout error on find": godriver2123SkipReason,
57-
"Network error on minPoolSize background creation": godriver2123SkipReason,
58-
}
59-
)
45+
var defaultHeartbeatInterval = 500 * time.Millisecond
6046

6147
type testFile struct {
6248
RunOn []mtest.RunOnBlock `bson:"runOn"`
@@ -257,9 +243,7 @@ func runSpecTestCase(mt *mtest.T, test *testCase, testFile testFile) {
257243
if len(test.SkipReason) > 0 {
258244
mt.Skip(test.SkipReason)
259245
}
260-
if skipReason, ok := skippedTestDescriptions[test.Description]; ok {
261-
mt.Skipf("skipping due to known failure: %v", skipReason)
262-
}
246+
spectest.CheckSkip(mt.T)
263247

264248
// work around for SERVER-39704: run a non-transactional distinct against each shard in a sharded cluster
265249
if mtest.ClusterTopologyKind() == mtest.Sharded && test.Description == "distinct" {

internal/serverselector/server_selector_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,7 @@ func runTest(t *testing.T, testsDir string, directory string, filename string) {
296296
content, err := ioutil.ReadFile(filepath)
297297
require.NoError(t, err)
298298

299-
// Remove ".json" from filename.
300-
filename = filename[:len(filename)-5]
301-
testName := directory + "/" + filename + ":"
302-
303-
t.Run(testName, func(t *testing.T) {
299+
t.Run(directory+"/"+filename, func(t *testing.T) {
304300
var test testCase
305301
require.NoError(t, bson.UnmarshalExtJSON(content, true, &test))
306302

internal/spectest/skip.go

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package spectest
2+
3+
import "testing"
4+
5+
// skipTests is a map of fully-qualified test name to the reason for skipping
6+
// the test.
7+
var skipTests = map[string]string{
8+
"TestURIOptionsSpec/single-threaded-options.json/Valid_options_specific_to_single-threaded_drivers_are_parsed_correctly": "the Go Driver is not single-threaded.",
9+
// GODRIVER-2348: The wtimeoutMS write concern option is not supported.
10+
"TestURIOptionsSpec/concern-options.json/Valid_read_and_write_concern_are_parsed_correctly": "the wtimeoutMS write concern option is not supported",
11+
12+
// SPEC-1403: This test checks to see if the correct error is thrown when
13+
// auto encrypting with a server < 4.2. Currently, the test will fail
14+
// because a server < 4.2 wouldn't have mongocryptd, so Client construction
15+
// would fail with a mongocryptd spawn error.
16+
"TestUnifiedSpecs/client-side-encryption/legacy/maxWireVersion.json/operation_fails_with_maxWireVersion_<_8": "servers less than 4.2 do not have mongocryptd; see SPEC-1403",
17+
18+
// GODRIVER-2123: The two tests below use a failpoint and a socket or server
19+
// selection timeout. The timeout causes the eventual clearing of the
20+
// failpoint in the test runner to fail with an i/o timeout.
21+
"TestUnifiedSpecs/server-discovery-and-monitoring/unified/find-network-timeout-error.json/Ignore_network_timeout_error_on_find": "failpoints and timeouts together cause failures; see GODRIVER-2123",
22+
"TestUnifiedSpecs/server-discovery-and-monitoring/unified/minPoolSize-error.json/Network_error_on_minPoolSize_background_creation": "failpoints and timeouts together cause failures; see GODRIVER-2123",
23+
24+
// GODRIVER-1827: These 2 tests assert that in-use connections are not
25+
// closed until checked back into a closed pool, but the Go connection pool
26+
// aggressively closes in-use connections. That behavior is currently
27+
// required by the "Client.Disconnect" API, so skip the tests.
28+
"TestCMAPSpec/pool-close-destroy-conns.json/When_a_pool_is_closed,_it_MUST_first_destroy_all_available_connections_in_that_pool": "test requires that close does not aggressively close used connections",
29+
"TestCMAPSpec/pool-close-destroy-conns.json/must_destroy_checked_in_connection_if_pool_has_been_closed": "test requires that close does not aggressively close used connections",
30+
31+
// GODRIVER-1826: The load-balancer SDAM error handling test "errors during
32+
// authentication are processed" currently asserts that handshake errors
33+
// trigger events "pool cleared" then "connection closed". However, the
34+
// "error during minPoolSize population clears pool" test asserts that
35+
// handshake errors trigger events "connection closed" then "pool cleared".
36+
// The Go driver uses the same code path for creating all application
37+
// connections, so those opposing event orders cannot be satisfied
38+
// simultaneously.
39+
//
40+
// TODO(DRIVERS-1785): Re-enable this test once the spec test is updated to
41+
// use the same event order as the "errors during authentication are
42+
// processed" load-balancer SDAM spec test.
43+
"TestCMAPSpec/pool-create-min-size-error.json/error_during_minPoolSize_population_clears_pool": "event ordering is incompatible with load-balancer SDAM spec test (DRIVERS-1785)",
44+
45+
// GODRIVER-1826: The Go connection pool does not currently always deliver
46+
// connections created by maintain() to waiting check-outs. There is a race
47+
// condition between the goroutine started by maintain() to check-in a
48+
// requested connection and createConnections() picking up the next wantConn
49+
// created by the waiting check-outs. Most of the time, createConnections()
50+
// wins and starts creating new connections. That is not a problem for
51+
// general use cases, but it prevents the "threads blocked by maxConnecting
52+
// check out minPoolSize connections" test from passing.
53+
//
54+
// TODO(DRIVERS-2225): Re-enable this test once the spec test is updated to
55+
// support the Go pool minPoolSize maintain() behavior.
56+
"TestCMAPSpec/pool-checkout-minPoolSize-connection-maxConnecting.json/threads_blocked_by_maxConnecting_check_out_minPoolSize_connections": "test requires that connections established by minPoolSize are immediately used to satisfy check-out requests (DRIVERS-2225)",
57+
58+
// GODRIVER-1826: The Go connection pool currently delivers any available
59+
// connection to the earliest waiting check-out request, independent of if
60+
// that check-out request already requested a new connection. That behavior
61+
// is currently incompatible with the "threads blocked by maxConnecting
62+
// check out returned connections" test, which expects that check-out
63+
// requests that request a new connection cannot be satisfied by a check-in.
64+
//
65+
// TODO(DRIVERS-2223): Re-enable this test once the spec test is updated to
66+
// support the Go pool check-in behavior.
67+
"TestCMAPSpec/pool-checkout-returned-connection-maxConnecting.json/threads_blocked_by_maxConnecting_check_out_returned_connections": "test requires a checked-in connections cannot satisfy a check-out waiting on a new connection (DRIVERS-2223)",
68+
69+
// TODO(GODRIVER-2129): Re-enable this test once GODRIVER-2129 is done.
70+
"TestAuthSpec/connection-string.json/must_raise_an_error_when_the_hostname_canonicalization_is_invalid": "support will be added with GODRIVER-2129.",
71+
}
72+
73+
// CheckSkip checks if the fully-qualified test name matches a skipped test
74+
// name. If the test name matches, the reason is logged and the test is skipped.
75+
func CheckSkip(t *testing.T) {
76+
if reason := skipTests[t.Name()]; reason != "" {
77+
t.Skipf("Skipping due to known failure: %q", reason)
78+
}
79+
}

x/mongo/driver/auth/auth_spec_test.go

+38-43
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import (
1818
"go.mongodb.org/mongo-driver/v2/mongo/options"
1919
)
2020

21-
var skippedTests = map[string]string{
22-
// GODRIVER-3175: Support will be added with GODRIVER-2129.
23-
"must raise an error when the hostname canonicalization is invalid": "Support will be added with GODRIVER-2129.",
24-
}
25-
2621
type credential struct {
2722
Username string
2823
Password *string
@@ -53,53 +48,53 @@ func runTestsInFile(t *testing.T, dirname string, filename string) {
5348
var container testContainer
5449
require.NoError(t, json.Unmarshal(content, &container))
5550

56-
for _, testCase := range container.Tests {
57-
t.Run(filename, func(t *testing.T) {
58-
runTest(t, testCase)
59-
})
60-
}
51+
t.Run(filename, func(t *testing.T) {
52+
for _, testCase := range container.Tests {
53+
testCase := testCase // Capture range variable.
54+
55+
t.Run(testCase.Description, func(t *testing.T) {
56+
spectest.CheckSkip(t)
57+
58+
runTest(t, testCase)
59+
})
60+
}
61+
})
6162
}
6263

6364
func runTest(t *testing.T, test testCase) {
64-
if skipReason, ok := skippedTests[test.Description]; ok {
65-
t.Skipf("skipping due to known failure: %q", skipReason)
66-
}
67-
68-
t.Run(test.Description, func(t *testing.T) {
69-
opts := options.Client().ApplyURI(test.URI)
65+
opts := options.Client().ApplyURI(test.URI)
7066

71-
if test.Valid {
72-
require.NoError(t, opts.Validate())
73-
} else {
74-
require.Error(t, opts.Validate())
67+
if test.Valid {
68+
require.NoError(t, opts.Validate())
69+
} else {
70+
require.Error(t, opts.Validate())
7571

76-
return
77-
}
72+
return
73+
}
7874

79-
if test.Credential == nil {
80-
require.Nil(t, opts.Auth)
81-
return
82-
}
83-
require.NotNil(t, opts.Auth)
84-
require.Equal(t, test.Credential.Username, opts.Auth.Username)
85-
86-
if test.Credential.Password == nil {
87-
require.False(t, opts.Auth.PasswordSet)
88-
} else {
89-
require.True(t, opts.Auth.PasswordSet)
90-
require.Equal(t, *test.Credential.Password, opts.Auth.Password)
91-
}
75+
if test.Credential == nil {
76+
require.Nil(t, opts.Auth)
77+
return
78+
}
79+
require.NotNil(t, opts.Auth)
80+
require.Equal(t, test.Credential.Username, opts.Auth.Username)
81+
82+
if test.Credential.Password == nil {
83+
require.False(t, opts.Auth.PasswordSet)
84+
} else {
85+
require.True(t, opts.Auth.PasswordSet)
86+
require.Equal(t, *test.Credential.Password, opts.Auth.Password)
87+
}
9288

93-
require.Equal(t, test.Credential.Source, opts.Auth.AuthSource)
89+
require.Equal(t, test.Credential.Source, opts.Auth.AuthSource)
9490

95-
require.Equal(t, test.Credential.Mechanism, opts.Auth.AuthMechanism)
91+
require.Equal(t, test.Credential.Mechanism, opts.Auth.AuthMechanism)
9692

97-
if len(test.Credential.MechProps) > 0 {
98-
require.Equal(t, mapInterfaceToString(test.Credential.MechProps), opts.Auth.AuthMechanismProperties)
99-
} else {
100-
require.Equal(t, 0, len(opts.Auth.AuthMechanismProperties))
101-
}
102-
})
93+
if len(test.Credential.MechProps) > 0 {
94+
require.Equal(t, mapInterfaceToString(test.Credential.MechProps), opts.Auth.AuthMechanismProperties)
95+
} else {
96+
require.Equal(t, 0, len(opts.Auth.AuthMechanismProperties))
97+
}
10398
}
10499

105100
// Convert each interface{} value in the map to a string.

0 commit comments

Comments
 (0)