diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 987e8c33d5..6361999b7a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -26,6 +26,8 @@ You need the Dotnet SDK to compile the main server and command line programs. In The recommended IDE is visual studio 2017 which has installation options for both of these. +In order to run the integration tests you must have the environment variables `TGS4_TEST_DATABASE_TYPE` set to `MySql` or `SqlServer` and `TGS4_TEST_CONNECTION_STRING` set appropriately + ## Meet the Team **Headcoder** diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index 018cd8d897..054414d29f 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -27,7 +27,26 @@ namespace Tgstation.Server.Tests var serverTask = server.RunAsync(cancellationToken); try { - using (var adminClient = await clientFactory.CreateServerClient(server.Url, User.AdminName, User.DefaultAdminPassword).ConfigureAwait(false)) + IServerClient adminClient; + + var giveUpAt = DateTimeOffset.Now.AddSeconds(30); + do + { + try + { + adminClient = await clientFactory.CreateServerClient(server.Url, User.AdminName, User.DefaultAdminPassword).ConfigureAwait(false); + break; + } + catch (ServiceUnavailableException) + { + //migrating, to be expected + if (DateTimeOffset.Now > giveUpAt) + throw; + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); + } + } while (true); + + using (adminClient) { var serverInfo = await adminClient.Version(default).ConfigureAwait(false); diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index 4e1df5f740..1b1b3905f5 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using System.Globalization; using System.IO; using System.Threading; @@ -15,21 +16,32 @@ namespace Tgstation.Server.Tests public bool RestartRequested => realServer.RestartRequested; readonly IServer realServer; - readonly string databasePath; public TestingServer() { Directory = Path.GetTempFileName(); File.Delete(Directory); System.IO.Directory.CreateDirectory(Directory); - databasePath = Path.Combine(Directory, "TGS.db3"); Url = new Uri("http://localhost:5001"); + + //so we need a db + //we have to rely on env vars + var databaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE"); + var connectionString = Environment.GetEnvironmentVariable("TGS4_TEST_CONNECTION_STRING"); + + if (String.IsNullOrEmpty(databaseType)) + Assert.Fail("No database type configured in env var TGS4_TEST_DATABASE_TYPE!"); + + if (String.IsNullOrEmpty(connectionString)) + Assert.Fail("No connection string configured in env var TGS4_TEST_CONNECTION_STRING!"); + realServer = new ServerFactory().CreateServer(new string[] { "--urls", Url.ToString(), - "Database:DatabaseType=Sqlite", - String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString=Data Source={0}", databasePath) + String.Format(CultureInfo.InvariantCulture, "Database:DatabaseType={0}", databaseType), + String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString={0}", connectionString), + "Database:DropDatabase=true" ,"Database:NoMigrations=true" //TODO: remove this when migrations are added }, null); }