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

Test getMore integration test using one connection pool #2878

Merged
merged 35 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
913cb04
set pool size in client
chilagrow Jun 21, 2023
f916843
expose ClientOption to setup
chilagrow Jun 21, 2023
3e00842
rename and comment update
chilagrow Jun 23, 2023
04c75a6
use url.Values
chilagrow Jun 23, 2023
40a511f
tidy up
chilagrow Jun 26, 2023
2f1b735
add same client and different client connection tests
chilagrow Jun 26, 2023
5d0a147
update error message for same client tests
chilagrow Jun 26, 2023
9de04ca
skip test for feature not supported by FerretDB
chilagrow Jun 26, 2023
734d5bf
comment update
chilagrow Jun 26, 2023
962ed96
run subtests in parallel
chilagrow Jun 26, 2023
0a74652
merge
chilagrow Jun 27, 2023
b0e8761
test setup handles merging url with extra url.Values option
chilagrow Jun 27, 2023
733b144
use stresstest.Stress
chilagrow Jun 27, 2023
e6a30e5
add batchSize test for find and getMore
chilagrow Jun 27, 2023
c6811fe
add getMore test for using different client
chilagrow Jun 27, 2023
1b450c7
update test
chilagrow Jun 27, 2023
a21acef
Merge branch 'main' into issue-1807-analysis
chilagrow Jun 27, 2023
405e8c9
update commnet
chilagrow Jun 27, 2023
805fcb2
cleanup
chilagrow Jun 27, 2023
9e6b8e9
do not run session related tests in parallel
chilagrow Jun 27, 2023
1e1f975
refactor
chilagrow Jun 27, 2023
fe31dfd
fix
chilagrow Jun 27, 2023
baf6065
Merge branch 'main' into issue-1807-analysis
chilagrow Jun 27, 2023
aae64c8
separate mongodburi and setup listener from extra options
chilagrow Jun 28, 2023
a22d37c
refactoring func name
chilagrow Jun 28, 2023
1a65aac
update comments and rename
chilagrow Jun 28, 2023
0e7adb8
cleanup
chilagrow Jun 28, 2023
bb965f5
Merge branch 'main' into issue-1807-analysis
chilagrow Jun 28, 2023
a9ea919
Merge branch 'main' into issue-1807-analysis
AlekSi Jun 28, 2023
c2397d2
fix new linter
chilagrow Jun 28, 2023
d7d3b8e
Merge branch 'issue-1807-analysis' of github.com:chilagrow/FerretDB i…
chilagrow Jun 28, 2023
02f1d08
Merge branch 'main' into issue-1807-analysis
AlekSi Jun 28, 2023
d5df4e0
Tweak comment
AlekSi Jun 28, 2023
17db130
Simplify
AlekSi Jun 28, 2023
676af8a
Refactor
AlekSi Jun 28, 2023
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
Prev Previous commit
Next Next commit
test setup handles merging url with extra url.Values option
  • Loading branch information
chilagrow committed Jun 27, 2023
commit b0e876149305945248ae9116a8c45d33df87d6d7
11 changes: 5 additions & 6 deletions integration/commands_diagnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,13 @@ func TestCommandsDiagnosticWhatsMyURI(t *testing.T) {
func TestCommandWhatsMyURIConnection(t *testing.T) {
t.Parallel()

// set 1 to ensure only one pool exists duration of the test,
// set minPoolSize and maxPoolSize 1 to ensure only one pool exists duration of the test,
// which forces a client to use a single connection pool
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
q1 := url.Values{}
q1.Set("maxPoolSize", "1")
q1.Set("minPoolSize", "1")

s := setup.SetupWithOpts(t, &setup.SetupOpts{
ExtraOptions: q1,
ExtraOptions: url.Values{
"minPoolSize": []string{"1"},
"maxPoolSize": []string{"1"},
},
})

collection1 := s.Collection
Expand Down
25 changes: 5 additions & 20 deletions integration/setup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,9 @@ func mongoDBURI(tb testing.TB, opts *mongoDBURIOpts) string {
return u.String()
}

// makeClient returns new client for the given MongoDB URI and extra options.
// The extraOpts that comes later overwrites value for the query key.
func makeClient(ctx context.Context, uri string, extraOpts url.Values) (*mongo.Client, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}

q := u.Query()

for k, vs := range extraOpts {
for _, v := range vs {
q.Set(k, v)
}
}

u.RawQuery = q.Encode()
clientOpts := options.Client().ApplyURI(u.String())
// makeClient returns new client for the given working MongoDB URI.
func makeClient(ctx context.Context, uri string) (*mongo.Client, error) {
clientOpts := options.Client().ApplyURI(uri)
clientOpts.SetMonitor(otelmongo.NewMonitor())

client, err := mongo.Connect(ctx, clientOpts)
Expand All @@ -117,15 +102,15 @@ func makeClient(ctx context.Context, uri string, extraOpts url.Values) (*mongo.C
//
// If the connection can't be established, it panics,
// as it doesn't make sense to proceed with other tests if we couldn't connect in one of them.
func setupClient(tb testing.TB, ctx context.Context, uri string, extraOpts url.Values) *mongo.Client {
func setupClient(tb testing.TB, ctx context.Context, uri string) *mongo.Client {
tb.Helper()

ctx, span := otel.Tracer("").Start(ctx, "setupClient")
defer span.End()

defer observability.FuncCall(ctx)()

client, err := makeClient(ctx, uri, extraOpts)
client, err := makeClient(ctx, uri)
if err != nil {
tb.Error(err)
panic("setupClient: " + err.Error())
Expand Down
2 changes: 1 addition & 1 deletion integration/setup/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func setupListener(tb testing.TB, ctx context.Context, logger *zap.Logger) (*mon
// those will fail the test if in-process FerretDB is not working;
// for example, when backend is down
uri := mongoDBURI(tb, &clientOpts)
client := setupClient(tb, ctx, uri, nil)
client := setupClient(tb, ctx, uri)

logger.Info("Listener started", zap.String("handler", handler), zap.String("uri", uri))

Expand Down
13 changes: 12 additions & 1 deletion integration/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ func SetupWithOpts(tb testing.TB, opts *SetupOpts) *SetupResult {
if *targetURLF == "" {
client, uri = setupListener(tb, setupCtx, logger)
} else {
client = setupClient(tb, setupCtx, *targetURLF, opts.ExtraOptions)
u, err := url.Parse(*targetURLF)
require.NoError(tb, err)

q := u.Query()
for k, vs := range opts.ExtraOptions {
for _, v := range vs {
q.Set(k, v)
}
}

u.RawQuery = q.Encode()
client = setupClient(tb, setupCtx, u.String())
uri = *targetURLF
}

Expand Down
4 changes: 2 additions & 2 deletions integration/setup/setup_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func SetupCompatWithOpts(tb testing.TB, opts *SetupCompatOpts) *SetupCompatResul
if *targetURLF == "" {
targetClient, _ = setupListener(tb, setupCtx, logger)
} else {
targetClient = setupClient(tb, setupCtx, *targetURLF, nil)
targetClient = setupClient(tb, setupCtx, *targetURLF)
}

// register cleanup function after setupListener registers its own to preserve full logs
tb.Cleanup(cancel)

targetCollections := setupCompatCollections(tb, setupCtx, targetClient, opts, *targetBackendF)

compatClient := setupClient(tb, setupCtx, *compatURLF, nil)
compatClient := setupClient(tb, setupCtx, *compatURLF)
compatCollections := setupCompatCollections(tb, setupCtx, compatClient, opts, "mongodb")

level.SetLevel(*logLevelF)
Expand Down
4 changes: 2 additions & 2 deletions integration/setup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Startup() {
must.NoError(os.MkdirAll(sqliteDir, 0o777))

if u := *targetURLF; u != "" {
client, err := makeClient(ctx, u, nil)
client, err := makeClient(ctx, u)
if err != nil {
zap.S().Fatalf("Failed to connect to target system %s: %s", u, err)
}
Expand All @@ -94,7 +94,7 @@ func Startup() {
}

if u := *compatURLF; u != "" {
client, err := makeClient(ctx, u, nil)
client, err := makeClient(ctx, u)
if err != nil {
zap.S().Fatalf("Failed to connect to compat system %s: %s", u, err)
}
Expand Down