Skip to content
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
18 changes: 11 additions & 7 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ timeout:
args: [ls, -la]

functions:
assume-test-secrets-ec2-role:
- command: ec2.assume_role
params:
role_arn: ${aws_test_secrets_role}

Comment on lines -29 to -33
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Duplicate of L175

setup-system:
# Executes clone and applies the submitted patch, if any
- command: git.get_project
Expand Down Expand Up @@ -439,7 +434,7 @@ functions:
params:
binary: "bash"
env:
TEST_SEARCH_INDEX: "${MONGODB_URI}"
SEARCH_INDEX_URI: "${SEARCH_INDEX_URI}"
args: [*task-runner, evg-test-search-index]

add-aws-auth-variables-to-file:
Expand Down Expand Up @@ -2063,7 +2058,7 @@ task_groups:
params:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, MONGODB_URI]
env:
MONGODB_VERSION: ${VERSION}
LAMBDA_STACK_NAME: dbx-go-lambda
Expand All @@ -2072,6 +2067,15 @@ task_groups:
- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
- command: shell.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
shell: bash
script: |-
echo "SEARCH_INDEX_URI: ${MONGODB_URI}" > atlas-expansion.yml
Copy link
Member

@prestonvasquez prestonvasquez Dec 1, 2025

Choose a reason for hiding this comment

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

[blocking] The EG changes seem to be trying to avoid using TEST_SEARCH_INDEX: "${MONGODB_URI}". If that's the case, we should keep the existing behavior for simplicity and roll TestSearchIndex into TestSearchIndexProse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TestSearchIndexProse only runs when SEARCH_INDEX_URI is set. This test requires being manually triggered here because it's time consuming. However, it was corrupted since 78b0f61

Copy link
Member

Choose a reason for hiding this comment

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

It seems that TestSearchIndexProse passes under the current TEST_SEARCH_INDEX paradigm, given the example you shared. So why do we need to add the SEARCH_INDEX_URI changes?

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 current codebase completely skips TestSearchIndexProse because MONGODB_URI is not set even in the test-search-index. The patch here is to set MONGODB_URI in the atlas env.

I also changed the value name from TEST_SEARCH_INDEX to SEARCH_INDEX_URI to avoid the misunderstandings in 78b0f61.

- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
teardown_group:
- command: subprocess.exec
params:
Expand Down
5 changes: 2 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# See https://taskfile.dev/usage/
version: '3'
version: "3"

env:
TEST_TIMEOUT: 1800
LONG_TEST_TIMEOUT: 3600

dotenv: ['.test.env']
dotenv: [".test.env"]

tasks:

### Utility tasks. ###
default:
deps: [build, check-license, check-fmt, check-modules, lint, test-short]
Expand Down
135 changes: 104 additions & 31 deletions internal/integration/search_index_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSearchIndexProse(t *testing.T) {

const timeout = 5 * time.Minute

uri := os.Getenv("TEST_INDEX_URI")
uri := os.Getenv("SEARCH_INDEX_URI")
if uri == "" {
t.Skip("skipping")
}
Expand All @@ -57,20 +57,23 @@ func TestSearchIndexProse(t *testing.T) {
require.NoError(mt, err, "failed to create index")
require.Equal(mt, searchName, index, "unmatched name")

awaitCtx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(awaitCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(awaitCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()
if name == searchName && queryable {
doc = cursor.Current
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand Down Expand Up @@ -110,7 +113,7 @@ func TestSearchIndexProse(t *testing.T) {
require.Contains(mt, indexes, *args.Name)
}

getDocument := func(opts *options.SearchIndexesOptionsBuilder) bson.Raw {
getDocument := func(ctx context.Context, opts *options.SearchIndexesOptionsBuilder) bson.Raw {
for {
cursor, err := view.List(ctx, opts)
require.NoError(mt, err, "failed to list")
Expand All @@ -127,7 +130,7 @@ func TestSearchIndexProse(t *testing.T) {
if name == *args.Name && queryable {
return cursor.Current
}
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand All @@ -138,7 +141,10 @@ func TestSearchIndexProse(t *testing.T) {
go func(opts *options.SearchIndexesOptionsBuilder) {
defer wg.Done()

doc := getDocument(opts)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

doc := getDocument(ctx, opts)
require.NotNil(mt, doc, "got empty document")

args, err := mongoutil.NewOptions[options.SearchIndexesOptions](opts)
Expand Down Expand Up @@ -173,35 +179,39 @@ func TestSearchIndexProse(t *testing.T) {
require.NoError(mt, err, "failed to create index")
require.Equal(mt, searchName, index, "unmatched name")

createOneCtx, createOneCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer createOneCancel()
var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(createOneCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(createOneCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()
if name == searchName && queryable {
doc = cursor.Current
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
require.NotNil(mt, doc, "got empty document")

err = view.DropOne(ctx, searchName)
require.NoError(mt, err, "failed to drop index")
dropOneCtx, dropOneCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer dropOneCancel()
for {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(dropOneCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(dropOneCtx) {
break
}
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
})
Expand All @@ -224,20 +234,22 @@ func TestSearchIndexProse(t *testing.T) {
require.NoError(mt, err, "failed to create index")
require.Equal(mt, searchName, index, "unmatched name")

createOneCtx, createOneCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer createOneCancel()
var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(createOneCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(createOneCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()
if name == searchName && queryable {
doc = cursor.Current
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand All @@ -248,11 +260,13 @@ func TestSearchIndexProse(t *testing.T) {
require.NoError(mt, err, "failed to marshal definition")
err = view.UpdateOne(ctx, searchName, definition)
require.NoError(mt, err, "failed to update index")
updateOneCtx, updateOneCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer updateOneCancel()
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(updateOneCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(updateOneCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
Expand All @@ -262,7 +276,7 @@ func TestSearchIndexProse(t *testing.T) {
if name == searchName && queryable && status == "READY" && bytes.Equal(latestDefinition, expected) {
doc = cursor.Current
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand Down Expand Up @@ -302,20 +316,22 @@ func TestSearchIndexProse(t *testing.T) {
})
require.NoError(mt, err, "failed to create index")
require.Equal(mt, searchName, index, "unmatched name")
awaitCtx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(awaitCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(awaitCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()
if name == searchName && queryable {
doc = cursor.Current
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand Down Expand Up @@ -348,12 +364,14 @@ func TestSearchIndexProse(t *testing.T) {
})
require.NoError(mt, err, "failed to create index")
require.Equal(mt, indexName, index, "unmatched name")
implicitCtx, implicitCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer implicitCancel()
var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(implicitCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(implicitCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
Expand All @@ -363,7 +381,7 @@ func TestSearchIndexProse(t *testing.T) {
doc = cursor.Current
assert.Equal(mt, indexType, "search")
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand All @@ -376,12 +394,14 @@ func TestSearchIndexProse(t *testing.T) {
})
require.NoError(mt, err, "failed to create index")
require.Equal(mt, indexName, index, "unmatched name")
explicitCtx, explicitCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer explicitCancel()
doc = nil
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(explicitCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(explicitCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
Expand All @@ -391,7 +411,7 @@ func TestSearchIndexProse(t *testing.T) {
doc = cursor.Current
assert.Equal(mt, indexType, "search")
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand All @@ -417,12 +437,14 @@ func TestSearchIndexProse(t *testing.T) {
})
require.NoError(mt, err, "failed to create index")
require.Equal(mt, indexName, index, "unmatched name")
vectorCtx, vectorCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer vectorCancel()
doc = nil
for doc == nil {
cursor, err := view.List(ctx, opts)
cursor, err := view.List(vectorCtx, opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
if !cursor.Next(vectorCtx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
Expand All @@ -432,7 +454,7 @@ func TestSearchIndexProse(t *testing.T) {
doc = cursor.Current
assert.Equal(mt, indexType, "vectorSearch")
} else {
t.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
Expand Down Expand Up @@ -472,4 +494,55 @@ func TestSearchIndexProse(t *testing.T) {
})
assert.ErrorContains(mt, err, "Attribute mappings missing")
})

mt.Run("case 9: Drivers use server default for unspecified name (`default`) and type (`search`)", func(mt *mtest.T) {
cases := []struct {
name string
opts *options.SearchIndexesOptionsBuilder
}{
{name: "empty options", opts: options.SearchIndexes()},
{name: "nil options", opts: nil},
}

for _, tc := range cases {
mt.Run(tc.name, func(mt *mtest.T) {
view := mt.Coll.SearchIndexes()
definition := bson.D{
{"mappings", bson.D{
{"dynamic", true},
}},
}

indexName, err := view.CreateOne(context.Background(), mongo.SearchIndexModel{
Definition: definition,
Options: tc.opts,
})
require.NoError(mt, err, "failed to create index")
require.Equal(mt, "default", indexName)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

var doc bson.Raw
for doc == nil {
cursor, err := view.List(ctx, tc.opts)
require.NoError(mt, err, "failed to list")

if !cursor.Next(ctx) {
break
}
name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()
indexType := cursor.Current.Lookup("type").StringValue()
if name == indexName && queryable {
doc = cursor.Current
require.Equal(mt, indexType, "search")
} else {
mt.Logf("cursor: %s, sleep 5 seconds...", cursor.Current.String())
time.Sleep(5 * time.Second)
}
}
})
}
})
}
Loading
Loading