Skip to content

Commit 3364c0c

Browse files
authored
Add PostgreSQL tests into GitHub action workflow. Fix a few breaking changes in PostgreSQL driver (#226)
* Configure PostgreSQL testing * Ignore non-public AuthIds * Fiix Schema extracting * test-postgres.yaml * Add Github Action * Replace pghost -> localhost * PGSERVICE * Rearrange * PGSERVICE * Merqe Postgres Tests with SQL Server tests * Add env vars * Fix BindDateTime() * Run Xtensive.Orm.Tests for both: Postgres & SQL Server * Mute Issue0713_InconsistentDefaultDateTimeValues * revert some changes * DateTimeOffsetConstructorTest * MutePostgreSqlAttribute * Correct filter string * Correct filter string * Correct filter string * Correct filter string * Mute a few Postgres tests * Mute a few Postgres tests * SET TIME ZONE UTC * SET TIME ZONE UTC * set-timezone github action * Mute
1 parent af6f9c0 commit 3364c0c

File tree

22 files changed

+106
-35
lines changed

22 files changed

+106
-35
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
runs-on: ubuntu-latest
1111
timeout-minutes: 60
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414
- name: Setup .NET
15-
uses: actions/setup-dotnet@v3
15+
uses: actions/setup-dotnet@v4
1616
with:
1717
dotnet-version: 8
1818
- name: Build

.github/workflows/dotnet_build_master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: Setup .NET
16-
uses: actions/setup-dotnet@v3
16+
uses: actions/setup-dotnet@v4
1717
with:
1818
dotnet-version: 8.0.x
1919
- name: Restore dependencies

.github/workflows/test-sql.yaml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
name: Tests with SQL Server
1+
name: Tests with PostgreSQL & SQL Server
22
on:
33
pull_request:
44
branches: [ master-servicetitan ]
55
env:
6+
DOTNET_CLI_TELEMETRY_OPTOUT: true
67
DO_CONFIG_FILE: "/tmp/do-test.cfg"
78
DO_TargetFrameworks: net8.0
89
SQL_PASSWD: dbatools.I0
@@ -12,21 +13,44 @@ jobs:
1213
runs-on: ubuntu-latest
1314
timeout-minutes: 120
1415
steps:
15-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
17+
- uses: szenius/[email protected]
18+
with:
19+
timezoneLinux: "UTC"
1620
- name: Setup .NET
17-
uses: actions/setup-dotnet@v3
21+
uses: actions/setup-dotnet@v4
1822
with: { dotnet-version: 8 }
1923
- name: Build SQL Docker image with FTS feature
2024
run: docker build -t sql .github/actions/mssql-fts
25+
- uses: ikalnytskyi/action-setup-postgres@v6
26+
- name: Init PostgreSQL Test DB
27+
run: |
28+
createuser dotest
29+
createdb --owner dotest dotest
30+
psql -c "ALTER USER dotest WITH PASSWORD 'dotest' SUPERUSER"
31+
env:
32+
PGSERVICE: postgres
2133
- name: Run SQL Server container
2234
run: docker run -e ACCEPT_EULA=Y -e MSSQL_PID='Developer' -e MSSQL_SA_PASSWORD=${SQL_PASSWD} -p 1433:1433 -d sql
2335
- name: Build
2436
run: dotnet build -v q Orm.sln
2537
- name: Init Test DB
2638
run: sqlcmd -U sa -P $SQL_PASSWD -C -i Orm/Xtensive.Orm.Tests.Framework/DO-Tests.sql && sqlcmd -U sa -P $SQL_PASSWD -C -i Orm/Xtensive.Orm.Tests.Framework/DO-Tests-Plus.sql
27-
- name: Create DO Tests Config file
39+
- name: Create PostgreSQL DO Tests Config file
40+
run: echo default=postgresql://dotest:dotest@localhost/dotest >$DO_CONFIG_FILE
41+
- name: Xtensive.Orm.Tests.Sql with PostgreSQL
42+
run: dotnet test --no-build -v n Orm/Xtensive.Orm.Tests.Sql/Xtensive.Orm.Tests.Sql.csproj --filter 'TestCategory!=Mute'
43+
env:
44+
DO_STORAGE: pgsql160
45+
- name: Xtensive.Orm.Tests with PostgreSQL
46+
run: dotnet test --no-build -v n Orm/Xtensive.Orm.Tests/Xtensive.Orm.Tests.csproj --filter '(TestCategory!=Mute)&(TestCategory!=MutePostgreSql)'
47+
env:
48+
DO_STORAGE: pgsql160
49+
- name: Create SQL Server DO Tests Config file
2850
run: echo default=sqlserver://sa:${SQL_PASSWD}@localhost/DO-Tests?MultipleActiveResultSets=True >$DO_CONFIG_FILE
29-
- name: Tests
51+
- name: Xtensive.Orm.Tests with SQL Server
3052
run: dotnet test --no-build -v n Orm/Xtensive.Orm.Tests/Xtensive.Orm.Tests.csproj --filter 'TestCategory!=Mute'
53+
env:
54+
DO_STORAGE: default
3155

3256

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/DriverFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ protected override SqlDriver CreateDriver(string connectionString, SqlDriverConf
6464
OpenConnectionFast(connection, configuration, false).GetAwaiter().GetResult();
6565
var version = GetVersion(configuration, connection);
6666
var defaultSchema = GetDefaultSchema(connection);
67+
SqlHelper.ExecuteInitializationSql(connection, @"SET TIME ZONE 'UTC'");
6768
return CreateDriverInstance(connectionString, version, defaultSchema);
6869
}
6970

@@ -79,6 +80,7 @@ protected override async Task<SqlDriver> CreateDriverAsync(
7980
await OpenConnectionFast(connection, configuration, true, token).ConfigureAwait(false);
8081
var version = GetVersion(configuration, connection);
8182
var defaultSchema = await GetDefaultSchemaAsync(connection, token: token).ConfigureAwait(false);
83+
await SqlHelper.ExecuteInitializationSqlAsync(connection, @"SET TIME ZONE 'UTC'", token);
8284
return CreateDriverInstance(connectionString, version, defaultSchema);
8385
}
8486
}

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Compiler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ internal class Compiler : SqlCompiler
4242
public override void Visit(SqlDeclareCursor node)
4343
{
4444
}
45-
4645
/// <inheritdoc/>
4746
public override void Visit(SqlOpenCursor node) => base.Visit(node.Cursor.Declare());
4847

@@ -574,4 +573,4 @@ protected internal Compiler(SqlDriver driver)
574573
{
575574
}
576575
}
577-
}
576+
}

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Extractor.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,18 @@ protected virtual void ReadSchemaData(DbDataReader dataReader, ExtractionContext
514514
{
515515
var oid = Convert.ToInt64(dataReader["oid"]);
516516
var name = dataReader["nspname"].ToString();
517-
var owner = Convert.ToInt64(dataReader["nspowner"]);
517+
var ownerOid = Convert.ToInt64(dataReader["nspowner"]);
518518

519519
var catalog = context.Catalog;
520520
var schema = catalog.Schemas[name] ?? catalog.CreateSchema(name);
521521
if (name == "public") {
522522
catalog.DefaultSchema = schema;
523523
}
524524

525-
schema.Owner = context.UserLookup[owner];
525+
if (context.UserLookup.TryGetValue(ownerOid, out var ownerName)) {
526+
schema.Owner = ownerName;
527+
}
528+
526529
context.SchemaMap[oid] = schema;
527530
context.ReversedSchemaMap[schema] = oid;
528531
}
@@ -1432,4 +1435,4 @@ public Extractor(SqlDriver driver)
14321435
{
14331436
}
14341437
}
1435-
}
1438+
}

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Translator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public override void Translate(SqlCompilerContext context, SqlDeclareCursor node
445445
case DeclareCursorSection.Exit:
446446
break;
447447
case DeclareCursorSection.For:
448-
_ = output.Append("FOR");
448+
_ = output.Append("FOR ");
449449
break;
450450
default:
451451
base.Translate(context, node, section);

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/TypeMapper.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,31 @@ public override void BindGuid(DbParameter parameter, object value)
124124
parameter.Value = value == null ? (object) DBNull.Value : SqlHelper.GuidToString((Guid) value);
125125
}
126126

127+
public override void BindDateTime(DbParameter parameter, object value)
128+
{
129+
parameter.DbType = DbType.DateTime2;
130+
if (value is DateTime dt) {
131+
// ((NpgsqlParameter) parameter).NpgsqlDbType = NpgsqlDbType.TimestampTz;
132+
var utc = dt.Kind switch {
133+
DateTimeKind.Local => dt.ToUniversalTime(),
134+
DateTimeKind.Utc => dt,
135+
_ => DateTime.SpecifyKind(dt, DateTimeKind.Utc)
136+
};
137+
var unspec = DateTime.SpecifyKind(utc, DateTimeKind.Unspecified);
138+
parameter.Value = unspec;
139+
}
140+
else {
141+
parameter.Value = DBNull.Value;
142+
}
143+
}
144+
127145
[SecuritySafeCritical]
128146
public override void BindDateTimeOffset(DbParameter parameter, object value)
129147
{
130-
var nativeParameter = (NpgsqlParameter) parameter;
131-
nativeParameter.NpgsqlDbType = NpgsqlDbType.TimestampTz;
132-
nativeParameter.NpgsqlValue = value ?? DBNull.Value;
148+
if (value is DateTimeOffset dto) {
149+
value = dto.ToUniversalTime();
150+
}
151+
base.BindDateTimeOffset(parameter, value);
133152
}
134153

135154
public override SqlValueType MapByte(int? length, int? precision, int? scale)
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using NUnit.Framework;
22

3-
namespace Xtensive.Orm.Tests
4-
{
5-
public class MuteAttribute : CategoryAttribute
6-
{
7-
public MuteAttribute() : base("Mute") {}
8-
}
9-
}
3+
namespace Xtensive.Orm.Tests;
4+
5+
public class MuteAttribute() : CategoryAttribute("Mute");
6+
7+
public class MutePostgreSqlAttribute() : CategoryAttribute("MutePostgreSql");

Orm/Xtensive.Orm.Tests.Framework/Orm.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
<domain name="pgsql150"
7373
connectionUrl="postgresql://dotest:dotest@localhost:54150/dotest" />
7474

75+
<domain name="pgsql160"
76+
connectionUrl="postgresql://dotest:dotest@localhost:5432/dotest" />
77+
78+
<domain name="pgsql160pghost"
79+
connectionUrl="postgresql://dotest:dotest@pghost:5432/dotest" />
80+
7581
<domain name="oracle10"
7682
connectionUrl="oracle://dotest:dotest@localhost:5510/ora10" />
7783

@@ -167,6 +173,12 @@
167173
<domain name="pgsql150cs" provider="postgresql"
168174
connectionString="HOST=localhost;PORT=54150;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest" />
169175

176+
<domain name="pgsql160cs" provider="postgresql"
177+
connectionString="HOST=localhost;PORT=5432;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest" />
178+
179+
<domain name="pgsql160pghostcs" provider="postgresql"
180+
connectionString="HOST=pghost;PORT=5432;DATABASE=dotest;USER ID=dotest;PASSWORD=dotest" />
181+
170182
<domain name="oracle10cs" provider="oracle"
171183
connectionString="DATA SOURCE=&quot;(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=5510))(CONNECT_DATA=(SERVICE_NAME=ora10)))&quot;;USER ID=dotest;PASSWORD=dotest" />
172184

0 commit comments

Comments
 (0)