Update mongodb unit tests

pull/5174/head
liangshiwei 4 years ago
parent 8ed7db41ba
commit 178bde4cee

@ -1,87 +0,0 @@
using System;
using System.Threading;
using MongoDB.Driver;
namespace Volo.Abp.MongoDB
{
/// <summary>
/// TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
/// </summary>
public static class MongoClientExtension
{
private static readonly TimeSpan InitialDelay = TimeSpan.FromMilliseconds(500);
private static readonly TimeSpan MaxDelay = TimeSpan.FromSeconds(5000);
public static void EnsureReplicationSetReady(this IMongoClient mongoClient)
{
var delay = InitialDelay;
var database = mongoClient.GetDatabase("__dummy-db");
try
{
while (true)
{
try
{
_ = database.GetCollection<DummyEntry>("__dummy");
database.DropCollection("__dummy");
var session = mongoClient.StartSession();
try
{
session.StartTransaction();
session.AbortTransaction();
}
finally
{
session.Dispose();
}
break;
}
catch (NotSupportedException)
{
}
Thread.Sleep(delay);
delay = Min(Double(delay), MaxDelay);
}
}
finally
{
mongoClient.DropDatabase("__dummy-db");
}
}
private static TimeSpan Min(TimeSpan left, TimeSpan right)
{
return new TimeSpan(Math.Min(left.Ticks, right.Ticks));
}
private static TimeSpan Double(TimeSpan timeSpan)
{
long ticks;
try
{
ticks = checked(timeSpan.Ticks * 2);
}
catch (OverflowException)
{
if (timeSpan.Ticks >= 0)
{
return TimeSpan.MaxValue;
}
return TimeSpan.MinValue;
}
return new TimeSpan(ticks);
}
private sealed class DummyEntry
{
public int Id { get; set; }
}
}
}

@ -1,5 +1,9 @@
using System;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp;
@ -32,6 +36,14 @@ namespace Volo.Abp.MongoDB
options.AddDefaultRepositories<ITestAppMongoDbContext>();
options.AddRepository<City, CityRepository>();
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,14 @@ namespace Volo.Abp.AuditLogging.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.AuditLogging.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,14 @@ namespace Volo.Abp.BackgroundJobs.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.BackgroundJobs.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.BackgroundJobs.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -7,7 +11,7 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
[DependsOn(
typeof(BlobStoringDatabaseTestBaseModule),
typeof(BlobStoringDatabaseMongoDbModule)
)]
)]
public class BlobStoringDatabaseMongoDbTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -18,10 +22,16 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.BlobStoring.Database.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -18,10 +22,16 @@ namespace Volo.Blogging.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Blogging.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Blogging.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -7,7 +11,7 @@ namespace Volo.CmsKit.MongoDB
[DependsOn(
typeof(CmsKitTestBaseModule),
typeof(CmsKitMongoDbModule)
)]
)]
public class CmsKitMongoDbTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -18,10 +22,16 @@ namespace Volo.CmsKit.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.CmsKit.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.CmsKit.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -18,10 +22,16 @@ namespace Volo.Docs.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Docs.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Docs.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,14 @@ namespace Volo.Abp.FeatureManagement.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.FeatureManagement.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.FeatureManagement.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,8 +1,11 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement.MongoDB;
using Volo.Abp.Uow;
namespace Volo.Abp.Identity.MongoDB
{
@ -10,7 +13,7 @@ namespace Volo.Abp.Identity.MongoDB
typeof(AbpIdentityTestBaseModule),
typeof(AbpPermissionManagementMongoDbModule),
typeof(AbpIdentityMongoDbModule)
)]
)]
public class AbpIdentityMongoDbTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -21,11 +24,16 @@ namespace Volo.Abp.Identity.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.Identity.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Identity.MongoDB;
using Volo.Abp.IdentityServer.MongoDB;
@ -26,6 +30,14 @@ namespace Volo.Abp.IdentityServer
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.IdentityServer
{
@ -14,10 +12,6 @@ namespace Volo.Abp.IdentityServer
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -17,10 +21,16 @@ namespace Volo.Abp.PermissionManagement.MongoDB
"Db_" +
Guid.NewGuid().ToString("N") + "/?" + stringArray[1];
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
Configure<AbpDbConnectionOptions>(options => { options.ConnectionStrings.Default = connectionString; });
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() =>
client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.PermissionManagement.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.PermissionManagement.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,14 @@ namespace Volo.Abp.SettingManagement.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace Volo.Abp.SettingManagement.MongoDB
{
@ -14,10 +12,6 @@ namespace Volo.Abp.SettingManagement.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,14 @@ namespace Volo.Abp.TenantManagement.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/100
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -14,10 +14,6 @@ namespace Volo.Abp.TenantManagement.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace MyCompanyName.MyProjectName.MongoDB
{
@ -14,9 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,13 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

@ -1,7 +1,5 @@
using System;
using Mongo2Go;
using MongoDB.Driver;
using Volo.Abp.MongoDB;
namespace MyCompanyName.MyProjectName.MongoDB
{
@ -14,10 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 10);
ConnectionString = MongoDbRunner.ConnectionString;
//TODO It can be removed, when Mongo2Go solves this issue : https://github.com/Mongo2Go/Mongo2Go/issues/89
var client = new MongoClient(MongoDbRunner.ConnectionString);
client.EnsureReplicationSetReady();
}
public void Dispose()

@ -1,4 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using MongoDB.Driver;
using MongoDB.Driver.Core.Servers;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
@ -22,6 +26,13 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
options.ConnectionStrings.Default = connectionString;
});
EnsureTransactionIsReady(new MongoClient(connectionString));
}
private void EnsureTransactionIsReady(MongoClient client)
{
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Any(s => s.State == ServerState.Connected && s.IsDataBearing));
}
}
}

Loading…
Cancel
Save