Skip to content

Commit

Permalink
e2e wip
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Aug 9, 2023
1 parent 7b4cd75 commit 318f5ef
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 84 deletions.
38 changes: 17 additions & 21 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,18 @@ functions:
params:
file: lb-expansion.yml

run-search-index-tests:
- command: shell.exec
type: test
params:
shell: "bash"
working_dir: src/go.mongodb.org/mongo-driver
script: |
${PREPARE_SHELL}
SEARCH_INDEX_TEST=1 \
MONGODB_URI="${MONGODB_URI}" \
make evg-test-search-index
stop-load-balancer:
- command: shell.exec
params:
Expand Down Expand Up @@ -2273,22 +2285,11 @@ tasks:
- name: "test-aws-searchindex-deployed"
commands:
- command: ec2.assume_role
params:
role_arn: ${LAMBDA_AWS_ROLE_ARN}
duration_seconds: 3600
- command: shell.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
shell: bash
add_expansions_to_env: true
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/internal/test/searchindex
LAMBDA_STACK_NAME: dbx-go-lambda
AWS_REGION: us-east-1
script: |
${PREPARE_SHELL}
./.evergreen/run-deployed-lambda-aws-tests.sh
- func: "bootstrap-mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "replica_set"
- func: "run-search-index-tests"

axes:
- id: version
Expand Down Expand Up @@ -2657,8 +2658,6 @@ task_groups:
binary: bash
add_expansions_to_env: true
env:
LAMBDA_STACK_NAME: dbx-go-lambda
AWS_REGION: us-east-1
MONGODB_VERSION: "7.0"
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
Expand All @@ -2671,9 +2670,6 @@ task_groups:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
add_expansions_to_env: true
env:
LAMBDA_STACK_NAME: dbx-go-lambda
AWS_REGION: us-east-1
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
setup_group_can_fail_task: true
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ evg-test-load-balancers:
go test $(BUILD_TAGS) ./mongo/integration -run TestLoadBalancerSupport -v -timeout $(TEST_TIMEOUT)s >> test.suite
go test $(BUILD_TAGS) ./mongo/integration/unified -run TestUnifiedSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite

.PHONY: evg-test-search-index
evg-test-search-index:
go test ./mongo -run TestSearchIndexProse -v -timeout $(TEST_TIMEOUT)s

.PHONY: evg-test-ocsp
evg-test-ocsp:
go test -v ./mongo -run TestOCSP $(OCSP_TLS_SHOULD_SUCCEED) >> test.suite
Expand Down
1 change: 0 additions & 1 deletion internal/test/searchindex/mongodb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.20
replace go.mongodb.org/mongo-driver => ../../../../

require (
github.com/aws/aws-lambda-go v1.41.0
github.com/google/uuid v1.3.0
// Note that the Go driver version is replaced with the local Go driver code
// by the replace directive above.
Expand Down
5 changes: 0 additions & 5 deletions internal/test/searchindex/mongodb/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
Expand All @@ -12,8 +10,6 @@ github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQ
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
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 Down Expand Up @@ -56,4 +52,3 @@ 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=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
81 changes: 24 additions & 57 deletions internal/test/searchindex/mongodb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/google/uuid"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand All @@ -24,83 +20,54 @@ import (

const timeout = 5 * time.Minute

// response is the data we return in the body of the API Gateway response.
type response struct {
Index string `json:"index"`
Cursor string `json:"cursor"`
}

// gateway500 is a convenience function for constructing a gateway response with
// a 500 status code, indicating an internal server error.
func gateway500() events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusInternalServerError,
Body: http.StatusText(http.StatusInternalServerError),
}

}

// handler is the AWS Lambda handler, executing at runtime.
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
func main() {
ctx := context.Background()

clientOptions := options.Client().ApplyURI(os.Getenv("MONGODB_URI")).
uri := os.Getenv("MONGODB_URI")
clientOptions := options.Client().ApplyURI(uri).
SetTimeout(timeout)

// Create a MongoClient that points to MONGODB_URI and listens to the
// ComandMonitor, ServerMonitor, and PoolMonitor events.
client, err := mongo.Connect(ctx, clientOptions)
if err != nil {
return gateway500(), fmt.Errorf("failed to create client: %w", err)
panic(fmt.Errorf("failed to connect %s: %w", uri, err))
}
defer client.Disconnect(ctx)

db := client.Database("test")
collName := fmt.Sprintf("col%s", uuid.New().String())
err = db.CreateCollection(ctx, collName)
if err != nil {
return gateway500(), fmt.Errorf("failed to create collection: %w", err)
}

collection := client.Database("test").Collection(collName)
defer collection.Drop(ctx)

_, err = collection.InsertOne(ctx, bson.D{})
if err != nil {
panic(fmt.Errorf("failed to insert: %w", err))
}

view := collection.SearchIndexes()

definition := bson.D{{"mappings", bson.D{{"dynamic", false}}}}
searchName := "test-search-index"
index, err := view.CreateOne(ctx, mongo.SearchIndexModel{
Definition: bson.D{{"mappings", bson.D{{"dynamic", false}}}},
Definition: definition,
Name: &searchName,
})
if err != nil {
return gateway500(), fmt.Errorf("failed to create index: %w", err)
panic(fmt.Errorf("failed to create index: %w", err))
}

time.Sleep(20 * time.Second)

cursor, err := view.List(ctx, nil, nil)
cursor, err := view.List(ctx, &index, nil)
if err != nil {
return gateway500(), fmt.Errorf("failed to list: %w", err)
panic(fmt.Errorf("failed to list: %w", err))
}

rsp := &response{
Index: index,
Cursor: cursor.Current.String(),
}

body, err := json.Marshal(rsp)
if err != nil {
return gateway500(), fmt.Errorf("failed to marshal: %w", err)
for i := 0; i < 3; i++ {
if !cursor.Next(ctx) {
panic(fmt.Errorf("expected aggregate to return a document, but got none"))
}
if cursor.Current.Lookup("name").StringValue() == searchName && cursor.Current.Lookup("queryable").Boolean() {
break
}
time.Sleep(5 * time.Second)
}

return events.APIGatewayProxyResponse{
Body: string(body),
StatusCode: http.StatusOK,
}, nil
}

func main() {
ctx := context.Background()

lambda.StartWithOptions(handler, lambda.WithContext(ctx))
}
65 changes: 65 additions & 0 deletions mongo/search_index_prose_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package mongo

import (
"context"
"fmt"
"os"
"testing"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/uuid"
"go.mongodb.org/mongo-driver/mongo/options"
)

func TestSearchIndexProse(t *testing.T) {
if os.Getenv("SEARCH_INDEX_TEST") == "" {
t.Skip("skipping")
}

const timeout = 5 * time.Minute

ctx := context.Background()

uri := os.Getenv("MONGODB_URI")
clientOptions := options.Client().ApplyURI(uri).SetTimeout(timeout)

// Create a MongoClient that points to MONGODB_URI and listens to the
// ComandMonitor, ServerMonitor, and PoolMonitor events.
client, err := Connect(ctx, clientOptions)
assert.NoError(t, err, "failed to connect %s", uri)
defer client.Disconnect(ctx)

id, err := uuid.New()
assert.NoError(t, err)
collName := fmt.Sprintf("col%s", id.String())
collection := client.Database("test").Collection(collName)
defer collection.Drop(ctx)

_, err = collection.InsertOne(ctx, bson.D{})
assert.NoError(t, err, "failed to insert")

view := collection.SearchIndexes()

definition := bson.D{{"mappings", bson.D{{"dynamic", false}}}}
searchName := "test-search-index"
index, err := view.CreateOne(ctx, SearchIndexModel{
Definition: definition,
Name: &searchName,
})
assert.NoError(t, err, "failed to create index")

cursor, err := view.List(ctx, &index, nil)
assert.NoError(t, err, "failed to list")

for i := 0; i < 3; i++ {
if !cursor.Next(ctx) {
assert.Fail(t, "expected aggregate to return a document, but got none")
}
if cursor.Current.Lookup("name").StringValue() == searchName && cursor.Current.Lookup("queryable").Boolean() {
break
}
time.Sleep(5 * time.Second)
}
}

0 comments on commit 318f5ef

Please sign in to comment.