From a86b40056d705bca1b6fde8e3b463779166041ae Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Tue, 29 Nov 2022 18:37:00 +0100 Subject: [PATCH 1/4] Do not skip tests if DB setup failed --- .../StorageTests/MySqlRelationalStoreTests.cs | 11 ++--------- test/TesterInternal/ConnectionStringFixture.cs | 13 +++---------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/test/Extensions/TesterAdoNet/StorageTests/MySqlRelationalStoreTests.cs b/test/Extensions/TesterAdoNet/StorageTests/MySqlRelationalStoreTests.cs index 876d7c7d9f..bf93c47b0d 100644 --- a/test/Extensions/TesterAdoNet/StorageTests/MySqlRelationalStoreTests.cs +++ b/test/Extensions/TesterAdoNet/StorageTests/MySqlRelationalStoreTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -20,14 +20,7 @@ public class Fixture { public Fixture() { - try - { - Storage = RelationalStorageForTesting.SetupInstance(AdoNetInvariantName, TestDatabaseName).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to initialize {AdoNetInvariantName} for testing: {ex}"); - } + Storage = RelationalStorageForTesting.SetupInstance(AdoNetInvariantName, TestDatabaseName).GetAwaiter().GetResult(); } public RelationalStorageForTesting Storage { get; private set; } diff --git a/test/TesterInternal/ConnectionStringFixture.cs b/test/TesterInternal/ConnectionStringFixture.cs index 76be21253f..fe97635810 100644 --- a/test/TesterInternal/ConnectionStringFixture.cs +++ b/test/TesterInternal/ConnectionStringFixture.cs @@ -25,17 +25,10 @@ public string ConnectionString $"{nameof(InitializeConnectionStringAccessor)} was not called before accessing the connection string"); } - try + var connString = this.connectionStringLazy.Value.Result; + if (connString != null) { - var connString = this.connectionStringLazy.Value.Result; - if (connString != null) - { - return connString; - } - } - catch (Exception ex) - { - throw new SkipException("Environment is not correctly set up to run these tests. " + ex); + return connString; } throw new SkipException("Environment is not correctly set up to run these tests. Connection string is empty."); From f03a43c6b5fd302a6f96f2c2771b7e650975ff3b Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Tue, 29 Nov 2022 18:42:08 +0100 Subject: [PATCH 2/4] Pin mariadb version to 10.6 (LTS) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e925736bf..c8eeb5aa0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,7 +107,7 @@ jobs: provider: ["MySql"] services: mariadb: - image: mariadb + image: mariadb:10.6 ports: - 3306:3306 env: From 30f7040480ae6389340a7a1c7dc55732d281b213 Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Tue, 29 Nov 2022 20:25:16 +0100 Subject: [PATCH 3/4] Skip MembershipTableTests when no connection string configured --- .../MySqlStorageForTesting.cs | 4 +-- .../PostgreSqlStorageForTesting.cs | 4 +-- .../RelationalStorageForTesting.cs | 31 +++++++------------ .../SqlServerStorageForTesting.cs | 4 +-- .../MembershipTableTestsBase.cs | 4 +++ 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/test/Extensions/TesterAdoNet/RelationalUtilities/MySqlStorageForTesting.cs b/test/Extensions/TesterAdoNet/RelationalUtilities/MySqlStorageForTesting.cs index e8889fb15d..033c321a24 100644 --- a/test/Extensions/TesterAdoNet/RelationalUtilities/MySqlStorageForTesting.cs +++ b/test/Extensions/TesterAdoNet/RelationalUtilities/MySqlStorageForTesting.cs @@ -10,7 +10,7 @@ namespace UnitTests.General internal class MySqlStorageForTesting : RelationalStorageForTesting { protected override string ProviderMoniker => "MySQL"; - public MySqlStorageForTesting(string connectionString) : base(AdoNetInvariants.InvariantNameMySql, connectionString) + public MySqlStorageForTesting(string connectionString) : base(AdoNetInvariants.InvariantNameMySql, connectionString ?? TestDefaultConfiguration.MySqlConnectionString) { } @@ -33,8 +33,6 @@ protected override string DropDatabaseTemplate { get { return @"DROP DATABASE `{0}`"; } } - - public override string DefaultConnectionString => TestDefaultConfiguration.MySqlConnectionString; protected override string ExistsDatabaseTemplate { diff --git a/test/Extensions/TesterAdoNet/RelationalUtilities/PostgreSqlStorageForTesting.cs b/test/Extensions/TesterAdoNet/RelationalUtilities/PostgreSqlStorageForTesting.cs index 61889b9343..1f0623e3fe 100644 --- a/test/Extensions/TesterAdoNet/RelationalUtilities/PostgreSqlStorageForTesting.cs +++ b/test/Extensions/TesterAdoNet/RelationalUtilities/PostgreSqlStorageForTesting.cs @@ -11,12 +11,10 @@ class PostgreSqlStorageForTesting : RelationalStorageForTesting protected override string ProviderMoniker => "PostgreSQL"; public PostgreSqlStorageForTesting(string connectionString) - : base(AdoNetInvariants.InvariantNamePostgreSql, connectionString) + : base(AdoNetInvariants.InvariantNamePostgreSql, connectionString ?? TestDefaultConfiguration.PostgresConnectionString) { } - public override string DefaultConnectionString => TestDefaultConfiguration.PostgresConnectionString; - public override string CancellationTestQuery { get { return "SELECT pg_sleep(10); SELECT 1; "; } } public override string CreateStreamTestTable { get { return "CREATE TABLE StreamingTest(Id integer NOT NULL, StreamData bytea NOT NULL);"; } } diff --git a/test/Extensions/TesterAdoNet/RelationalUtilities/RelationalStorageForTesting.cs b/test/Extensions/TesterAdoNet/RelationalUtilities/RelationalStorageForTesting.cs index bbf3c9171d..bf0b8b0005 100644 --- a/test/Extensions/TesterAdoNet/RelationalUtilities/RelationalStorageForTesting.cs +++ b/test/Extensions/TesterAdoNet/RelationalUtilities/RelationalStorageForTesting.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Orleans.Tests.SqlUtils; using Tester.RelationalUtilities; +using Xunit.Sdk; namespace UnitTests.General { @@ -22,7 +23,7 @@ public abstract class RelationalStorageForTesting public string CurrentConnectionString { - get { return Storage.ConnectionString; } + get { return Storage?.ConnectionString; } } /// @@ -30,11 +31,6 @@ public string CurrentConnectionString /// protected abstract string ProviderMoniker { get; } - /// - /// Default connection string for testing - /// - public abstract string DefaultConnectionString { get; } - /// /// A delayed query that is then cancelled in a test to see if cancellation works. /// @@ -99,16 +95,15 @@ public static async Task SetupInstance(string invar Console.WriteLine("Initializing relational databases..."); RelationalStorageForTesting testStorage; - if (connectionString == null) - { - testStorage = CreateTestInstance(invariantName); - } - else + testStorage = CreateTestInstance(invariantName, connectionString); + + if (string.IsNullOrEmpty(testStorage.CurrentConnectionString)) { - testStorage = CreateTestInstance(invariantName, connectionString); + Console.WriteLine("No storage configured"); + return testStorage; } - Console.WriteLine("Dropping and recreating database '{0}' with connectionstring '{1}'", testDatabaseName, connectionString ?? testStorage.DefaultConnectionString); + Console.WriteLine("Dropping and recreating database '{0}' with connectionstring '{1}'", testDatabaseName, testStorage.CurrentConnectionString); if (await testStorage.ExistsDatabaseAsync(testDatabaseName)) { @@ -145,11 +140,6 @@ private static RelationalStorageForTesting CreateTestInstance(string invariantNa return instanceFactory[invariantName](connectionString); } - private static RelationalStorageForTesting CreateTestInstance(string invariantName) - { - return CreateTestInstance(invariantName, CreateTestInstance(invariantName, "notempty").DefaultConnectionString); - } - /// /// Constructor /// @@ -157,7 +147,10 @@ private static RelationalStorageForTesting CreateTestInstance(string invariantNa /// protected RelationalStorageForTesting(string invariantName, string connectionString) { - Storage = RelationalStorage.CreateInstance(invariantName, connectionString); + if (!string.IsNullOrEmpty(connectionString)) + { + Storage = RelationalStorage.CreateInstance(invariantName, connectionString); + } } /// diff --git a/test/Extensions/TesterAdoNet/RelationalUtilities/SqlServerStorageForTesting.cs b/test/Extensions/TesterAdoNet/RelationalUtilities/SqlServerStorageForTesting.cs index b35a064fb9..dca9ad715b 100644 --- a/test/Extensions/TesterAdoNet/RelationalUtilities/SqlServerStorageForTesting.cs +++ b/test/Extensions/TesterAdoNet/RelationalUtilities/SqlServerStorageForTesting.cs @@ -11,12 +11,10 @@ public class SqlServerStorageForTesting : RelationalStorageForTesting protected override string ProviderMoniker => "SQLServer"; public SqlServerStorageForTesting(string connectionString) - : base(AdoNetInvariants.InvariantNameSqlServer, connectionString) + : base(AdoNetInvariants.InvariantNameSqlServer, connectionString ?? TestDefaultConfiguration.MsSqlConnectionString) { } - public override string DefaultConnectionString => TestDefaultConfiguration.MsSqlConnectionString; - public override string CancellationTestQuery { get { return "WAITFOR DELAY '00:00:010'; SELECT 1; "; } } public override string CreateStreamTestTable { get { return "CREATE TABLE StreamingTest(Id INT NOT NULL, StreamData VARBINARY(MAX) NOT NULL);"; } } diff --git a/test/TesterInternal/MembershipTests/MembershipTableTestsBase.cs b/test/TesterInternal/MembershipTests/MembershipTableTestsBase.cs index 7c48cebb77..541db86dde 100644 --- a/test/TesterInternal/MembershipTests/MembershipTableTestsBase.cs +++ b/test/TesterInternal/MembershipTests/MembershipTableTestsBase.cs @@ -59,6 +59,10 @@ protected MembershipTableTestsBase(ConnectionStringFixture fixture, TestEnvironm fixture.InitializeConnectionStringAccessor(GetConnectionString); this.connectionString = fixture.ConnectionString; + if (string.IsNullOrEmpty(this.connectionString)) + { + throw new SkipException("No connection string configured"); + } this.clusterOptions = Options.Create(new ClusterOptions { ClusterId = this.clusterId }); var adoVariant = GetAdoInvariant(); From 41dc7bb2df98111549ab70dff985ad84af6c99ac Mon Sep 17 00:00:00 2001 From: Benjamin Petit Date: Wed, 30 Nov 2022 11:04:20 +0100 Subject: [PATCH 4/4] Fix RelationalStoreTestsBase --- .../TesterAdoNet/StorageTests/RelationalStoreTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Extensions/TesterAdoNet/StorageTests/RelationalStoreTests.cs b/test/Extensions/TesterAdoNet/StorageTests/RelationalStoreTests.cs index a5ba2fc70a..bcc0247c74 100644 --- a/test/Extensions/TesterAdoNet/StorageTests/RelationalStoreTests.cs +++ b/test/Extensions/TesterAdoNet/StorageTests/RelationalStoreTests.cs @@ -30,7 +30,7 @@ public abstract class RelationalStoreTestsBase protected static Task[] InsertAndReadStreamsAndCheckMatch(RelationalStorageForTesting sut, int streamSize, int countOfStreams, CancellationToken cancellationToken) { - Skip.If(sut == null, "Database was not initialized correctly"); + Skip.If(string.IsNullOrEmpty(sut.CurrentConnectionString), "Database was not initialized correctly"); //Stream in and steam out three binary streams in parallel. var streamChecks = new Task[countOfStreams]; @@ -52,7 +52,7 @@ protected static Task[] InsertAndReadStreamsAndCheckMatch(RelationalStorag protected static async Task InsertIntoDatabaseUsingStream(RelationalStorageForTesting sut, int streamId, byte[] dataToInsert, CancellationToken cancellationToken) { - Skip.If(sut == null, "Database was not initialized correctly"); + Skip.If(string.IsNullOrEmpty(sut.CurrentConnectionString), "Database was not initialized correctly"); //The dataToInsert could be inserted here directly, but it wouldn't be streamed. using (var ms = new MemoryStream(dataToInsert)) { @@ -80,7 +80,7 @@ await sut.Storage.ExecuteAsync(sut.StreamTestInsert, command => protected static async Task ReadFromDatabaseUsingAsyncStream(RelationalStorageForTesting sut, int streamId, CancellationToken cancellationToken) { - Skip.If(sut == null, "Database was not initialized correctly"); + Skip.If(string.IsNullOrEmpty(sut.CurrentConnectionString), "Database was not initialized correctly"); return (await sut.Storage.ReadAsync(sut.StreamTestSelect, command => { var p = command.CreateParameter(); @@ -105,7 +105,7 @@ protected static async Task ReadFromDatabaseUsingAsyncStream(Rela protected static Task CancellationTokenTest(RelationalStorageForTesting sut, TimeSpan timeoutLimit) { - Skip.If(sut == null, "Database was not initialized correctly"); + Skip.If(string.IsNullOrEmpty(sut.CurrentConnectionString), "Database was not initialized correctly"); using (var tokenSource = new CancellationTokenSource(timeoutLimit)) { try