mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Make creating the database not take 2 whole seconds in integration tests (#45151)
* Make creating the database not take 2 whole seconds in integration tests * gramar
This commit is contained in:
parent
7c19a7d1de
commit
82e28037a6
5 changed files with 21 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ public static partial class PoolManager
|
|||
{
|
||||
// @formatter:off
|
||||
(CCVars.DatabaseSynchronous.Name, "true"),
|
||||
(CCVars.DatabaseSnapshot.Name, "true"),
|
||||
(CCVars.DatabaseSqliteDelay.Name, "0"),
|
||||
(CCVars.HolidaysEnabled.Name, "false"),
|
||||
(CCVars.GameMap.Name, TestMap),
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace Content.IntegrationTests.Tests.Preferences
|
|||
var conn = new SqliteConnection("Data Source=:memory:");
|
||||
conn.Open();
|
||||
builder.UseSqlite(conn);
|
||||
return new ServerDbSqlite(() => builder.Options, true, cfg, true, opsLog, serialization);
|
||||
return new ServerDbSqlite(() => builder.Options, true, cfg, true, opsLog, serialization, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -421,6 +421,7 @@ namespace Content.Server.Database
|
|||
private ISawmill _sawmill = default!;
|
||||
|
||||
private bool _synchronous;
|
||||
private bool _snapshot;
|
||||
// When running in integration tests, we'll use a single in-memory SQLite database connection.
|
||||
// This is that connection, close it when we shut down.
|
||||
private SqliteConnection? _sqliteInMemoryConnection;
|
||||
|
|
@ -437,6 +438,7 @@ namespace Content.Server.Database
|
|||
_sawmill = _logMgr.GetSawmill("db.manager");
|
||||
|
||||
_synchronous = _cfg.GetCVar(CCVars.DatabaseSynchronous);
|
||||
_snapshot = _cfg.GetCVar(CCVars.DatabaseSnapshot);
|
||||
|
||||
var engine = _cfg.GetCVar(CCVars.DatabaseEngine).ToLower();
|
||||
var opsLog = _logMgr.GetSawmill("db.op");
|
||||
|
|
@ -445,7 +447,7 @@ namespace Content.Server.Database
|
|||
{
|
||||
case "sqlite":
|
||||
SetupSqlite(out var contextFunc, out var inMemory);
|
||||
_db = new ServerDbSqlite(contextFunc, inMemory, _cfg, _synchronous, opsLog, _serialization);
|
||||
_db = new ServerDbSqlite(contextFunc, inMemory, _cfg, _synchronous, opsLog, _serialization, _snapshot);
|
||||
break;
|
||||
case "postgres":
|
||||
var (pgOptions, conString) = CreatePostgresOptions();
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ namespace Content.Server.Database
|
|||
IConfigurationManager cfg,
|
||||
bool synchronous,
|
||||
ISawmill opsLog,
|
||||
ISerializationManager serialization)
|
||||
ISerializationManager serialization,
|
||||
bool snapshot)
|
||||
: base(opsLog, serialization)
|
||||
{
|
||||
_options = options;
|
||||
|
|
@ -51,7 +52,12 @@ namespace Content.Server.Database
|
|||
|
||||
if (synchronous)
|
||||
{
|
||||
prefsCtx.Database.Migrate();
|
||||
// EnsureCreated means you can't apply migrations later, fine for tests
|
||||
if (snapshot)
|
||||
prefsCtx.Database.EnsureCreated();
|
||||
else
|
||||
prefsCtx.Database.Migrate();
|
||||
|
||||
_dbReadyTask = Task.CompletedTask;
|
||||
prefsCtx.Dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,12 @@ public sealed partial class CCVars
|
|||
/// </summary>
|
||||
public static readonly CVarDef<bool> DatabaseSynchronous =
|
||||
CVarDef.Create("database.sync", false, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the SQLite database using EnsureCreated instead of Migrate, if using SQLite.
|
||||
/// Setting this to true means you cannot apply migrations later.
|
||||
/// Meant to be used in integration tests only.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> DatabaseSnapshot =
|
||||
CVarDef.Create("database.snapshot", false, CVar.SERVERONLY);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue