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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Extensions.Configuration;

namespace MongoDB.ConformanceTests.Support;

#pragma warning disable CA1810 // Initialize all static fields when those fields are declared

internal static class MongoTestEnvironment
{
public static readonly string? ConnectionUrl;

public static bool IsConnectionInfoDefined => ConnectionUrl is not null;

static MongoTestEnvironment()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: true)
.AddJsonFile(path: "testsettings.development.json", optional: true)
.AddEnvironmentVariables()
.Build();

var mongoSection = configuration.GetSection("MongoDB");
ConnectionUrl = mongoSection["ConnectionURL"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ internal sealed class MongoTestStore : TestStore
{
public static MongoTestStore Instance { get; } = new();

private readonly MongoDbContainer _container = new MongoDbBuilder()
.WithImage("mongodb/mongodb-atlas-local:7.0.6")
.Build();
private MongoDbContainer? _container;

public MongoClient? _client { get; private set; }
public IMongoDatabase? _database { get; private set; }
Expand All @@ -32,21 +30,40 @@ private MongoTestStore()

protected override async Task StartAsync()
{
var clientSettings = MongoTestEnvironment.IsConnectionInfoDefined
? MongoClientSettings.FromConnectionString(MongoTestEnvironment.ConnectionUrl)
: await this.StartMongoDbContainerAsync();

this._client = new MongoClient(clientSettings);
this._database = this._client.GetDatabase("VectorSearchTests");
this.DefaultVectorStore = new MongoVectorStore(this._database);
}

private async Task<MongoClientSettings> StartMongoDbContainerAsync()
{
this._container = new MongoDbBuilder()
.WithImage("mongodb/mongodb-atlas-local:7.0.6")
.Build();

using CancellationTokenSource cts = new();
cts.CancelAfter(TimeSpan.FromSeconds(60));
await this._container.StartAsync(cts.Token);

this._client = new MongoClient(new MongoClientSettings
return new MongoClientSettings
{
Server = new MongoServerAddress(this._container.Hostname, this._container.GetMappedPublicPort(MongoDbBuilder.MongoDbPort)),
DirectConnection = true,
// ReadConcern = ReadConcern.Linearizable,
// WriteConcern = WriteConcern.WMajority
});
this._database = this._client.GetDatabase("VectorSearchTests");
this.DefaultVectorStore = new MongoVectorStore(this._database);
};
}

protected override Task StopAsync()
=> this._container.StopAsync();
protected override async Task StopAsync()
{
if (this._container != null)
{
await this._container.StopAsync();
this._container = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public virtual async Task WaitForDataAsync<TKey, TRecord>(

var vector = dummyVector ?? new ReadOnlyMemory<float>(Enumerable.Range(0, vectorSize ?? 3).Select(i => (float)i).ToArray());

for (var i = 0; i < 20; i++)
for (var i = 0; i < 200; i++)
{
var results = collection.SearchAsync(
vector,
Expand Down
Loading