Skip to content

Prevent integration tests from running when testing with -short #2116

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

Merged
merged 1 commit into from
Jun 27, 2025
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
4 changes: 4 additions & 0 deletions internal/integtest/integtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func AddServerlessAuthCredentials(uri string) (string, error) {

// ConnString gets the globally configured connection string.
func ConnString(t *testing.T) *connstring.ConnString {
if testing.Short() {
t.Skip("skipping integration test in short mode")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little strange to skip the tests from a helper function. Is it possible to skip from TestXXX()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to skip any tests that seem to be integration tests when using the -short test flag. We do something similar in mtest.New, which prevents us from having to add the if testing.Short() check in all the tests that use mtest.

We could add the if testing.Short() check to all tests individually, but that has been error-prone. Ideally all integration tests would use mtest, but tests in the mongo package can't import mtest, so integration tests are stuck using integtest.ConnString.

}

connectionStringOnce.Do(func() {
uri, err := MongoDBURI()
require.NoError(t, err, "error constructing mongodb URI: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions x/mongo/driver/topology/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func (d *timeoutDialer) DialContext(ctx context.Context, network, address string

// TestServerHeartbeatTimeout tests timeout retry and preemptive canceling.
func TestServerHeartbeatTimeout(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("Skipping this test in docker.")
}
Expand Down
Loading