Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Darling/Darling.Tests/ScratchPostgres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ internal sealed class ScratchPostgres : IAsyncDisposable

public string ConnectionString { get; }

private ScratchPostgres(string adminConnectionString, string databaseName, string connectionString)
/// <summary>
/// The same store WITHOUT the session time-zone pin, so a session opened through it reports the database's own
/// default zone. It exists for tests that must observe that default (e.g. to prove the product pin overrides it).
/// </summary>
public string UnpinnedConnectionString { get; }

private ScratchPostgres(string adminConnectionString, string databaseName, string connectionString, string unpinnedConnectionString)
{
UnpinnedConnectionString = unpinnedConnectionString;
_adminConnectionString = adminConnectionString;
DatabaseName = databaseName;
ConnectionString = connectionString;
Expand All @@ -48,7 +55,13 @@ public static async Task<ScratchPostgres> CreateAsync(string baseConnectionStrin
Pooling = false,
};

return new ScratchPostgres(baseConnectionString, databaseName, builder.ConnectionString);
/* Pinned to UTC the way every product store connection is, so a cluster whose default zone is behind UTC
cannot skew timestamp round trips (a chunk's range_end read back through a ::timestamp cast). */
return new ScratchPostgres(
baseConnectionString,
databaseName,
PerformanceMonitor.Darling.Storage.DarlingStoreConnection.PinSessionTimeZoneUtc(builder.ConnectionString),
builder.ConnectionString);
}

public async ValueTask DisposeAsync()
Expand Down
6 changes: 3 additions & 3 deletions Darling/Darling.Tests/StoreSessionTimeZoneLiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ shares DARLING_TEST_PG's own database. */

/* ALTER DATABASE ... SET only takes effect for sessions opened AFTER it commits, so migrate through a
fresh connection rather than the admin one above. */
await using (var migrate = new NpgsqlConnection(scratch.ConnectionString))
await using (var migrate = new NpgsqlConnection(scratch.UnpinnedConnectionString))
{
await migrate.OpenAsync(ct);
await PgMigrations.MigrateAsync(migrate, ct);
}

/* The database's own default, UNPINNED — confirms the fixture set up a genuinely non-UTC store
before asserting that the product's pin overrides it. */
await using (var unpinned = new NpgsqlConnection(scratch.ConnectionString))
await using (var unpinned = new NpgsqlConnection(scratch.UnpinnedConnectionString))
{
await unpinned.OpenAsync(ct);
Assert.Equal("America/New_York", await ShowTimeZoneAsync(unpinned, ct));
}

/* The way the product opens a STORE connection: PinSessionTimeZoneUtc first, then the connection. */
var pinnedConnectionString = DarlingStoreConnection.PinSessionTimeZoneUtc(scratch.ConnectionString);
var pinnedConnectionString = DarlingStoreConnection.PinSessionTimeZoneUtc(scratch.UnpinnedConnectionString);
await using var connection = new NpgsqlConnection(pinnedConnectionString);
await connection.OpenAsync(ct);

Expand Down
Loading