Skip to content

Commit

Permalink
test: implement fix for SQLite multithreading issue everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
BEagle1984 committed Sep 3, 2021
1 parent 92ded30 commit a3256e3
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public DbContextEventsPublisherTests()
{
_publisher = Substitute.For<IPublisher>();

_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();
var dbOptions = new DbContextOptionsBuilder<TestDbContext>()
.UseSqlite(_connection)
.UseSqlite(_connection.ConnectionString)
.Options;

_dbContext = new TestDbContext(dbOptions, _publisher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public TestDbContext GetTestDbContext()
{
if (_connection == null)
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();
}

var dbOptions = new DbContextOptionsBuilder<TestDbContext>()
.UseSqlite(_connection)
.UseSqlite(_connection.ConnectionString)
.Options;

var dbContext = new TestDbContext(dbOptions, Substitute.For<IPublisher>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class DbDistributedLockManagerTests : IDisposable

public DbDistributedLockManagerTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -33,7 +33,7 @@ public DbDistributedLockManagerTests()
.AddTransient<DbDistributedLockManager>()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddLoggerSubstitute()
.AddSilverback()
.UseDbContext<TestDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class DistributedBackgroundServiceTests : IDisposable

public DistributedBackgroundServiceTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -34,7 +34,7 @@ public DistributedBackgroundServiceTests()
.AddTransient<DbDistributedLockManager>()
.AddDbContext<TestDbContext>(
opt => opt
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddLoggerSubstitute()
.AddSilverback()
.UseDbContext<TestDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class RecurringDistributedBackgroundServiceTests : IDisposable

public RecurringDistributedBackgroundServiceTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -34,7 +34,7 @@ public RecurringDistributedBackgroundServiceTests()
.AddTransient<DbDistributedLockManager>()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddLoggerSubstitute()
.AddSilverback()
.UseDbContext<TestDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public sealed class DbEventStoreRepositoryTests : IDisposable

public DbEventStoreRepositoryTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

_dbContext = new TestDbContext(new DbContextOptionsBuilder().UseSqlite(_connection).Options);
_dbContext = new TestDbContext(new DbContextOptionsBuilder().UseSqlite(_connection.ConnectionString).Options);
_dbContext.Database.EnsureCreated();

SilverbackQueryableExtensions.Implementation = new EfCoreQueryableExtensions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class DbInboundLogTests : IDisposable

public DbInboundLogTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -39,7 +39,7 @@ public DbInboundLogTests()
.AddLoggerSubstitute()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddSilverback()
.UseDbContext<TestDbContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class DbOffsetStoreTests : IDisposable

public DbOffsetStoreTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -39,7 +39,7 @@ public DbOffsetStoreTests()
.AddLoggerSubstitute()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddSilverback()
.UseDbContext<TestDbContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class DbOutboxReaderTests : IDisposable

public DbOutboxReaderTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -54,7 +54,7 @@ public DbOutboxReaderTests()
.AddLoggerSubstitute()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddSilverback()
.UseDbContext<TestDbContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class DbOutboxWriterTests : IDisposable

public DbOutboxWriterTests()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared");
_connection.Open();

var services = new ServiceCollection();
Expand All @@ -50,7 +50,7 @@ public DbOutboxWriterTests()
.AddLoggerSubstitute()
.AddDbContext<TestDbContext>(
options => options
.UseSqlite(_connection))
.UseSqlite(_connection.ConnectionString))
.AddSilverback()
.UseDbContext<TestDbContext>();

Expand Down

0 comments on commit a3256e3

Please sign in to comment.