Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2667 Replacing the assert.Soon with the assert.Eventually function #1668

Merged
merged 19 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/test/compilecheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ replace go.mongodb.org/mongo-driver => ../../../
require go.mongodb.org/mongo-driver v1.11.7

require (
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
19 changes: 9 additions & 10 deletions internal/test/compilecheck/go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
Expand All @@ -17,16 +17,16 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -44,4 +44,3 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
152 changes: 60 additions & 92 deletions mongo/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,31 +526,23 @@ func TestClient(t *testing.T) {

// Assert that the minimum RTT is eventually >250ms.
topo := getTopologyFromClient(mt.Client)
assert.Soon(mt, func(ctx context.Context) {
for {
// Stop loop if callback has been canceled.
select {
case <-ctx.Done():
return
default:
}

time.Sleep(100 * time.Millisecond)

// Wait for all of the server's minimum RTTs to be >250ms.
done := true
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.Nil(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().Min() <= 250*time.Millisecond {
done = false
}
}
if done {
return
callback := func() bool {
// Wait for all of the server's minimum RTTs to be >250ms.
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.NoError(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().Min() <= 250*time.Millisecond {
return false // the tick should wait for 100ms in this case
}
}
}, 10*time.Second)

return true
}
assert.Eventually(t,
callback,
10*time.Second,
100*time.Millisecond,
"expected that the minimum RTT is eventually >250ms")
})

// Test that if the minimum RTT is greater than the remaining timeout for an operation, the
Expand All @@ -574,31 +566,23 @@ func TestClient(t *testing.T) {

// Assert that the minimum RTT is eventually >250ms.
topo := getTopologyFromClient(mt.Client)
assert.Soon(mt, func(ctx context.Context) {
for {
// Stop loop if callback has been canceled.
select {
case <-ctx.Done():
return
default:
}

time.Sleep(100 * time.Millisecond)

// Wait for all of the server's minimum RTTs to be >250ms.
done := true
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.Nil(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().Min() <= 250*time.Millisecond {
done = false
}
}
if done {
return
callback := func() bool {
timothy-kim-mongo marked this conversation as resolved.
Show resolved Hide resolved
// Wait for all of the server's minimum RTTs to be >250ms.
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.NoError(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().Min() <= 250*time.Millisecond {
return false
}
}
}, 10*time.Second)

return true
}
assert.Eventually(t,
callback,
10*time.Second,
100*time.Millisecond,
"expected that the minimum RTT is eventually >250ms")

// Once we've waited for the minimum RTT for the single server to be >250ms, run a bunch of
// Ping operations with a timeout of 250ms and expect that they return errors.
Expand All @@ -625,31 +609,23 @@ func TestClient(t *testing.T) {

// Assert that RTT90s are eventually >300ms.
topo := getTopologyFromClient(mt.Client)
assert.Soon(mt, func(ctx context.Context) {
for {
// Stop loop if callback has been canceled.
select {
case <-ctx.Done():
return
default:
}

time.Sleep(100 * time.Millisecond)

// Wait for all of the server's RTT90s to be >300ms.
done := true
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.Nil(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().P90() <= 300*time.Millisecond {
done = false
}
}
if done {
return
callback := func() bool {
// Wait for all of the server's RTT90s to be >300ms.
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.NoError(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().P90() <= 300*time.Millisecond {
return false
}
}
}, 10*time.Second)

return true
}
assert.Eventually(t,
callback,
10*time.Second,
100*time.Millisecond,
"expected that the RTT90s are eventually >300ms")
})

// Test that if Timeout is set and the RTT90 is greater than the remaining timeout for an operation, the
Expand All @@ -676,31 +652,23 @@ func TestClient(t *testing.T) {

// Assert that RTT90s are eventually >275ms.
topo := getTopologyFromClient(mt.Client)
assert.Soon(mt, func(ctx context.Context) {
for {
// Stop loop if callback has been canceled.
select {
case <-ctx.Done():
return
default:
}

time.Sleep(100 * time.Millisecond)

// Wait for all of the server's RTT90s to be >275ms.
done := true
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.Nil(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().P90() <= 275*time.Millisecond {
done = false
}
}
if done {
return
callback := func() bool {
// Wait for all of the server's RTT90s to be >275ms.
for _, desc := range topo.Description().Servers {
server, err := topo.FindServer(desc)
assert.NoError(mt, err, "FindServer error: %v", err)
if server.RTTMonitor().P90() <= 275*time.Millisecond {
return false
}
}
}, 10*time.Second)

return true
}
assert.Eventually(t,
callback,
10*time.Second,
100*time.Millisecond,
"expected that the RTT90s are eventually >275ms")

// Once we've waited for the RTT90 for the servers to be >275ms, run 10 Ping operations
// with a timeout of 275ms and expect that they return timeout errors.
Expand Down
52 changes: 36 additions & 16 deletions mongo/integration/csot_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,55 +89,75 @@ func TestCSOTProse(t *testing.T) {
mt.RunOpts("serverSelectionTimeoutMS honored if timeoutMS is not set", mtOpts, func(mt *mtest.T) {
mt.Parallel()

callback := func(ctx context.Context) {
err := mt.Client.Ping(ctx, nil)
assert.NotNil(mt, err, "expected Ping error, got nil")
callback := func() bool {
err := mt.Client.Ping(context.Background(), nil)
assert.Error(mt, err, "expected Ping error, got nil")
return true
}

// Assert that Ping fails within 150ms due to server selection timeout.
assert.Soon(mt, callback, 150*time.Millisecond)
assert.Eventually(t,
callback,
150*time.Millisecond,
time.Millisecond,
"expected ping to fail within 150ms")
})

cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=100&serverSelectionTimeoutMS=200")
mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false)
mt.RunOpts("timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS", mtOpts, func(mt *mtest.T) {
mt.Parallel()

callback := func(ctx context.Context) {
err := mt.Client.Ping(ctx, nil)
assert.NotNil(mt, err, "expected Ping error, got nil")
callback := func() bool {
err := mt.Client.Ping(context.Background(), nil)
assert.Error(mt, err, "expected Ping error, got nil")
return true
}

// Assert that Ping fails within 150ms due to timeout.
assert.Soon(mt, callback, 150*time.Millisecond)
assert.Eventually(t,
callback,
150*time.Millisecond,
time.Millisecond,
"expected ping to fail within 150ms")
})

cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=200&serverSelectionTimeoutMS=100")
mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false)
mt.RunOpts("serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS", mtOpts, func(mt *mtest.T) {
mt.Parallel()

callback := func(ctx context.Context) {
err := mt.Client.Ping(ctx, nil)
assert.NotNil(mt, err, "expected Ping error, got nil")
callback := func() bool {
err := mt.Client.Ping(context.Background(), nil)
assert.Error(mt, err, "expected Ping error, got nil")
return true
}

// Assert that Ping fails within 150ms due to server selection timeout.
assert.Soon(mt, callback, 150*time.Millisecond)
assert.Eventually(t,
callback,
150*time.Millisecond,
time.Millisecond,
"expected ping to fail within 150ms")
})

cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=100")
mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false)
mt.RunOpts("serverSelectionTimeoutMS honored for server selection if timeoutMS=0", mtOpts, func(mt *mtest.T) {
mt.Parallel()

callback := func(ctx context.Context) {
err := mt.Client.Ping(ctx, nil)
assert.NotNil(mt, err, "expected Ping error, got nil")
callback := func() bool {
err := mt.Client.Ping(context.Background(), nil)
assert.Error(mt, err, "expected Ping error, got nil")
return true
}

// Assert that Ping fails within 150ms due to server selection timeout.
assert.Soon(mt, callback, 150*time.Millisecond)
assert.Eventually(t,
callback,
150*time.Millisecond,
time.Millisecond,
"expected ping to fail within 150ms")
})
})
}
Loading
Loading