From a3256e38afa9d4102644e826f929173ff6f8b99c Mon Sep 17 00:00:00 2001 From: BEagle1984 Date: Fri, 3 Sep 2021 14:52:30 +0200 Subject: [PATCH] test: implement fix for SQLite multithreading issue everywhere --- .../DbContextEventsPublisherTests.cs | 4 ++-- .../TestTypes/TestDbContextInitializer.cs | 4 ++-- .../Background/DbDistributedLockManagerTests.cs | 4 ++-- .../Background/DistributedBackgroundServiceTests.cs | 4 ++-- .../Background/RecurringDistributedBackgroundServiceTests.cs | 4 ++-- .../EventStore/DbEventStoreRepositoryTests.cs | 4 ++-- .../Inbound/ExactlyOnce/Repositories/DbInboundLogTests.cs | 4 ++-- .../Inbound/ExactlyOnce/Repositories/DbOffsetStoreTests.cs | 4 ++-- .../TransactionalOutbox/Repositories/DbOutboxReaderTests.cs | 4 ++-- .../TransactionalOutbox/Repositories/DbOutboxWriterTests.cs | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/Silverback.Core.EfCore30.Tests/DbContextEventsPublisherTests.cs b/tests/Silverback.Core.EfCore30.Tests/DbContextEventsPublisherTests.cs index 8a278dd43..14b30c367 100644 --- a/tests/Silverback.Core.EfCore30.Tests/DbContextEventsPublisherTests.cs +++ b/tests/Silverback.Core.EfCore30.Tests/DbContextEventsPublisherTests.cs @@ -27,10 +27,10 @@ public DbContextEventsPublisherTests() { _publisher = Substitute.For(); - _connection = new SqliteConnection("DataSource=:memory:"); + _connection = new SqliteConnection($"Data Source={Guid.NewGuid():N};Mode=Memory;Cache=Shared"); _connection.Open(); var dbOptions = new DbContextOptionsBuilder() - .UseSqlite(_connection) + .UseSqlite(_connection.ConnectionString) .Options; _dbContext = new TestDbContext(dbOptions, _publisher); diff --git a/tests/Silverback.Core.EfCore30.Tests/TestTypes/TestDbContextInitializer.cs b/tests/Silverback.Core.EfCore30.Tests/TestTypes/TestDbContextInitializer.cs index 48f20d3f7..74eddad2a 100644 --- a/tests/Silverback.Core.EfCore30.Tests/TestTypes/TestDbContextInitializer.cs +++ b/tests/Silverback.Core.EfCore30.Tests/TestTypes/TestDbContextInitializer.cs @@ -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() - .UseSqlite(_connection) + .UseSqlite(_connection.ConnectionString) .Options; var dbContext = new TestDbContext(dbOptions, Substitute.For()); diff --git a/tests/Silverback.Core.Tests/Background/DbDistributedLockManagerTests.cs b/tests/Silverback.Core.Tests/Background/DbDistributedLockManagerTests.cs index 0881985ba..e499ffa20 100644 --- a/tests/Silverback.Core.Tests/Background/DbDistributedLockManagerTests.cs +++ b/tests/Silverback.Core.Tests/Background/DbDistributedLockManagerTests.cs @@ -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(); @@ -33,7 +33,7 @@ public DbDistributedLockManagerTests() .AddTransient() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddLoggerSubstitute() .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.Core.Tests/Background/DistributedBackgroundServiceTests.cs b/tests/Silverback.Core.Tests/Background/DistributedBackgroundServiceTests.cs index 70c2708a6..712755bb1 100644 --- a/tests/Silverback.Core.Tests/Background/DistributedBackgroundServiceTests.cs +++ b/tests/Silverback.Core.Tests/Background/DistributedBackgroundServiceTests.cs @@ -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(); @@ -34,7 +34,7 @@ public DistributedBackgroundServiceTests() .AddTransient() .AddDbContext( opt => opt - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddLoggerSubstitute() .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.Core.Tests/Background/RecurringDistributedBackgroundServiceTests.cs b/tests/Silverback.Core.Tests/Background/RecurringDistributedBackgroundServiceTests.cs index a3d73982f..0a531937f 100644 --- a/tests/Silverback.Core.Tests/Background/RecurringDistributedBackgroundServiceTests.cs +++ b/tests/Silverback.Core.Tests/Background/RecurringDistributedBackgroundServiceTests.cs @@ -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(); @@ -34,7 +34,7 @@ public RecurringDistributedBackgroundServiceTests() .AddTransient() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddLoggerSubstitute() .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.EventSourcing.Tests/EventStore/DbEventStoreRepositoryTests.cs b/tests/Silverback.EventSourcing.Tests/EventStore/DbEventStoreRepositoryTests.cs index 25a56bf02..2e2353ea8 100644 --- a/tests/Silverback.EventSourcing.Tests/EventStore/DbEventStoreRepositoryTests.cs +++ b/tests/Silverback.EventSourcing.Tests/EventStore/DbEventStoreRepositoryTests.cs @@ -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(); diff --git a/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbInboundLogTests.cs b/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbInboundLogTests.cs index 7c8a13515..291073f6c 100644 --- a/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbInboundLogTests.cs +++ b/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbInboundLogTests.cs @@ -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(); @@ -39,7 +39,7 @@ public DbInboundLogTests() .AddLoggerSubstitute() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbOffsetStoreTests.cs b/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbOffsetStoreTests.cs index 029bc2b73..16fbe744b 100644 --- a/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbOffsetStoreTests.cs +++ b/tests/Silverback.Integration.Tests/Messaging/Inbound/ExactlyOnce/Repositories/DbOffsetStoreTests.cs @@ -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(); @@ -39,7 +39,7 @@ public DbOffsetStoreTests() .AddLoggerSubstitute() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxReaderTests.cs b/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxReaderTests.cs index 41d1a641b..23cc6e411 100644 --- a/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxReaderTests.cs +++ b/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxReaderTests.cs @@ -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(); @@ -54,7 +54,7 @@ public DbOutboxReaderTests() .AddLoggerSubstitute() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddSilverback() .UseDbContext(); diff --git a/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxWriterTests.cs b/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxWriterTests.cs index b966f4bb6..f731bdc43 100644 --- a/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxWriterTests.cs +++ b/tests/Silverback.Integration.Tests/Messaging/Outbound/TransactionalOutbox/Repositories/DbOutboxWriterTests.cs @@ -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(); @@ -50,7 +50,7 @@ public DbOutboxWriterTests() .AddLoggerSubstitute() .AddDbContext( options => options - .UseSqlite(_connection)) + .UseSqlite(_connection.ConnectionString)) .AddSilverback() .UseDbContext();