diff --git a/Content.IntegrationTests/ContentIntegrationTest.cs b/Content.IntegrationTests/ContentIntegrationTest.cs index e1914cadc2..63c05143c7 100644 --- a/Content.IntegrationTests/ContentIntegrationTest.cs +++ b/Content.IntegrationTests/ContentIntegrationTest.cs @@ -4,6 +4,7 @@ using Content.Client; using Content.Client.Interfaces.Parallax; using Content.Server; using Content.Server.Interfaces.GameTicking; +using Content.Shared; using NUnit.Framework; using Robust.Server.Interfaces.Maps; using Robust.Server.Interfaces.Timing; @@ -76,6 +77,9 @@ namespace Content.IntegrationTests }); }; + // Avoid funny race conditions with the database. + options.CVarOverrides[CCVars.DatabaseSynchronous.Name] = "true"; + return base.StartServer(options); } diff --git a/Content.Server/Database/ServerDbSqlite.cs b/Content.Server/Database/ServerDbSqlite.cs index a51484a288..9e726240e0 100644 --- a/Content.Server/Database/ServerDbSqlite.cs +++ b/Content.Server/Database/ServerDbSqlite.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net; @@ -7,7 +6,10 @@ using System.Threading; using System.Threading.Tasks; using Content.Server.Preferences; using Content.Server.Utility; +using Content.Shared; using Microsoft.EntityFrameworkCore; +using Robust.Shared.Interfaces.Configuration; +using Robust.Shared.IoC; using Robust.Shared.Network; #nullable enable @@ -32,7 +34,15 @@ namespace Content.Server.Database { _prefsCtx = new SqliteServerDbContext(options); - _dbReadyTask = Task.Run(() => _prefsCtx.Database.Migrate()); + if (IoCManager.Resolve().GetCVar(CCVars.DatabaseSynchronous)) + { + _prefsCtx.Database.Migrate(); + _dbReadyTask = Task.CompletedTask; + } + else + { + _dbReadyTask = Task.Run(() => _prefsCtx.Database.Migrate()); + } } public override async Task GetServerBanAsync(IPAddress? address, NetUserId? userId) diff --git a/Content.Shared/CCVars.cs b/Content.Shared/CCVars.cs index db9b5bc90c..a9b88f87e7 100644 --- a/Content.Shared/CCVars.cs +++ b/Content.Shared/CCVars.cs @@ -142,6 +142,10 @@ namespace Content.Shared public static readonly CVarDef DatabasePgPassword = CVarDef.Create("database.pg_password", "", CVar.SERVERONLY); + // Basically only exists for integration tests to avoid race conditions. + public static readonly CVarDef DatabaseSynchronous = + CVarDef.Create("database.sync", false, CVar.SERVERONLY); + /* * Outline