Skip to content

Commit 4dedc8e

Browse files
authored
Merge pull request #412 from servicetitan/mergeUpstream
Merge upstream
2 parents 36c6563 + c2d0fb8 commit 4dedc8e

File tree

6 files changed

+165
-152
lines changed

6 files changed

+165
-152
lines changed

.github/workflows/reusable-storage-dependant-tests.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
target_framework:
1717
description: 'Target framework'
1818
required: true
19-
default: 'net6.0'
19+
default: 'net8.0'
2020
type: string
2121
specific_sha:
2222
description: 'Commit SHA to checkout'
@@ -158,14 +158,6 @@ jobs:
158158
run: |
159159
docker stop $(docker ps -a -q)
160160
161-
- name: Temp log output
162-
if: |
163-
!cancelled()
164-
run: |
165-
echo "github event name: ${{ github.event_name }}"
166-
echo "reproc step outcome: ${{ steps.reprocessing.outcome }}"
167-
echo "complex step outcome: ${{ steps.complex_tests.outcome }}"
168-
169161
- name: Publish raw test results as files
170162
if: |
171163
(!cancelled() && inputs.publish_raw_results) || failure()

.github/workflows/reusable-storage-independant-tests.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
target_framework:
1212
description: 'Target framework'
1313
required: true
14-
default: 'net6.0'
14+
default: 'net8.0'
1515
type: string
1616
test_output_verbosity:
1717
description: 'Verbosity for dotnet test command'
@@ -123,10 +123,9 @@ jobs:
123123

124124
- name: Make Final Test report
125125
if: |
126-
(github.event_name == 'push' && steps.complex_tests.outcome != 'cancelled')
127-
|| (github.event_name == 'pull_request' && steps.complex_tests.outcome != 'cancelled')
128-
|| (github.event_name == 'workflow_dispatch' && steps.complex_tests.outcome != 'cancelled')
129-
|| steps.complex_tests.outcome == 'failure'
126+
!cancelled()
127+
&& ((github.event_name == 'push') || (github.event_name == 'pull_request') || (github.event_name == 'workflow_dispatch')
128+
|| (steps.reprocessing.outcome == 'failure' || steps.complex_tests.outcome == 'failure'))
130129
timeout-minutes: 1
131130
uses: dorny/[email protected]
132131
with:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class DriverFactory : SqlDriverFactory
2323
{
2424
private const string DatabaseAndSchemaQuery = "select current_database(), current_schema()";
2525

26+
private readonly static Guid InstanceIdentifier;
27+
2628
private readonly static bool InfinityAliasForDatesEnabled;
2729
private readonly static bool LegacyTimestamptBehaviorEnabled;
2830

@@ -225,8 +227,10 @@ private static bool GetSwitchValueOrSet(string switchName, bool valueToSet)
225227

226228
static DriverFactory()
227229
{
228-
// Starging from Npgsql 6.0 they broke compatibility by forcefully replacing
229-
// DateTime.MinValue/MaxValue of parameters with -Infinity and Infinity values.
230+
InstanceIdentifier = Guid.NewGuid();
231+
232+
// Starting from Npgsql 6.0 they broke compatibility by forcefully replacing
233+
// DateTime.MinValue/MaxValue in parameters with -Infinity and Infinity values.
230234
// This new "feature", though doesn't affect reading/writing of values and equality/inequality
231235
// filters, breaks some of operations such as parts extraction, default values for columns
232236
// (which are constants and declared on high levels of abstraction) and some others.

Orm/Xtensive.Orm.Tests.Sql/PostgreSql/InfinityAliasTest.cs

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public sealed class InfinityAliasTest : SqlTest
2929
private TypeMapping dateTimeTypeMapping;
3030
private TypeMapping dateTimeOffsetTypeMapping;
3131

32+
private TimeSpan localTimezone;
33+
3234
protected override void CheckRequirements()
3335
{
3436
Require.ProviderIs(StorageProvider.PostgreSql);
@@ -39,6 +41,7 @@ protected override void TestFixtureSetUp()
3941
base.TestFixtureSetUp();
4042

4143
var localZone = DateTimeOffset.Now.ToLocalTime().Offset;
44+
localTimezone = localZone;
4245
var localZoneString = ((localZone < TimeSpan.Zero) ? "-" : "+") + localZone.ToString(@"hh\:mm");
4346
var initConnectionCommand = Connection.CreateCommand($"SET TIME ZONE INTERVAL '{localZoneString}' HOUR TO MINUTE");
4447
_ = initConnectionCommand.ExecuteNonQuery();
@@ -466,10 +469,14 @@ private void TestMinDateTimeOffsetSelectDatePart(bool isOn)
466469
DateTimeOffset.MinValue.Day,
467470
isOn);
468471

469-
// timezone for DateTimeOffset.MinValue value in postgre is set to 04:02:33, at least when instance is in UTC+5 timezone
472+
var serverSideHours = (localTimezone > TimeSpan.Zero)
473+
? localTimezone.Hours // positive zone
474+
: (localTimezone < TimeSpan.Zero)
475+
? 23 + localTimezone.Hours // negative zone
476+
: localTimezone.Hours; // UTC
470477
TestDateTimeOffsetPartExtraction(DateTimeOffsetMinValueTable, SqlDateTimeOffsetPart.Hour,
471-
5,
472-
isOn ? DateTimeOffset.MinValue.Hour : 5,
478+
serverSideHours,
479+
serverSideHours,
473480
isOn);
474481
TestDateTimeOffsetPartExtraction(DateTimeOffsetMinValueTable, SqlDateTimeOffsetPart.Minute,
475482
DateTimeOffset.MinValue.Minute,
@@ -546,27 +553,39 @@ public void DateTimeOffsetMaxSelectDatePartDateTest()
546553

547554
private void TestMaxDateTimeOffsetSelectDatePart(bool isOn)
548555
{
556+
var overflowHappens = localTimezone > TimeSpan.Zero;
557+
549558
// There is overflow of year because of PostgreSQL time zone functionality
559+
var overflowYearValue = overflowHappens ? 1 : 0;
550560
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Year,
551-
DateTimeOffset.MaxValue.Year + 1,
552-
(isOn) ? DateTimeOffset.MaxValue.Year : DateTimeOffset.MaxValue.Year + 1,
561+
DateTimeOffset.MaxValue.Year + overflowYearValue,
562+
DateTimeOffset.MaxValue.Year + overflowYearValue,
553563
isOn);
554564

555565
// there is value overflow to 01 in case of no aliases
566+
var serverSideMonths = (localTimezone > TimeSpan.Zero) ? 1 : 12;
556567
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Month,
557-
1,
558-
(isOn) ? DateTimeOffset.MaxValue.Month : 1,
568+
serverSideMonths,
569+
serverSideMonths,
559570
isOn);
571+
560572
// there is value overflow to 01 in case of no aliases
573+
var serverSideDays = (localTimezone > TimeSpan.Zero) ? 1 : 31;
561574
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Day,
562-
1,
563-
(isOn) ? DateTimeOffset.MaxValue.Day : 1,
575+
serverSideDays,
576+
serverSideDays,
564577
isOn);
565578

566579
// timezone for DateTimeOffset.MaxValue value in postgre is set to 04:59:59.999999, at least when instance is in UTC+5 timezone
580+
var serverSideHours = (localTimezone > TimeSpan.Zero)
581+
? localTimezone.Hours - 1 // positive zone
582+
: (localTimezone < TimeSpan.Zero)
583+
? 23 + localTimezone.Hours // negative zone
584+
: 23; // UTC
585+
567586
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Hour,
568-
4,
569-
(isOn) ? DateTimeOffset.MaxValue.Hour : 4,
587+
serverSideHours,
588+
serverSideHours,
570589
isOn);
571590
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Minute,
572591
DateTimeOffset.MaxValue.Minute,
@@ -587,22 +606,26 @@ private void TestDatePartExtraction(string table, SqlDatePart part, int expected
587606
using (var reader = command.ExecuteReader()) {
588607

589608
while (reader.Read()) {
590-
if (aliasesEnabled && part != SqlDatePart.Year) {
591-
// year from +-infinity -> +-infinity
609+
if (aliasesEnabled) {
610+
// +-infinify
611+
// year from +-infinity -> +-infinity (or 0 in case of versions older than 9.6)
592612
// month from +-infinity -> null (or 0 in case of versions older that 9.6)
593613
if (Driver.CoreServerInfo.ServerVersion >= StorageProviderVersion.PostgreSql96) {
594-
Assert.That(reader.IsDBNull(0));
614+
if (part != SqlDatePart.Year) {
615+
Assert.That(reader.IsDBNull(0));
616+
}
617+
else {
618+
var partValue = reader.GetDouble(0);
619+
Assert.That(double.IsInfinity(partValue), Is.True);
620+
}
595621
}
596622
else {
597623
var partValue = reader.GetDouble(0);
598624
Assert.That(partValue, Is.Zero);
599625
}
600626
}
601-
if (Driver.CoreServerInfo.ServerVersion < StorageProviderVersion.PostgreSql96) {
602-
var partValue = reader.GetDouble(0);
603-
Assert.That(partValue, Is.Zero);
604-
}
605627
else {
628+
// pure dates
606629
var partValue = reader.GetDouble(0);
607630
CheckPartNative(partValue, expectedValueNative, aliasesEnabled);
608631
}
@@ -632,21 +655,26 @@ private void TestDateTimePartExtraction(string table, SqlDateTimePart part, int
632655
using (var reader = command.ExecuteReader()) {
633656

634657
while (reader.Read()) {
635-
if (aliasesEnabled && part != SqlDateTimePart.Year) {
636-
// year from +-infinity -> +-infinity
658+
if (aliasesEnabled) {
659+
// +-infinify
660+
// year from +-infinity -> +-infinity (or 0 in case of versions older than 9.6)
637661
// month from +-infinity -> null (or 0 in case of versions older that 9.6)
638-
if (Driver.CoreServerInfo.ServerVersion >= StorageProviderVersion.PostgreSql96)
639-
Assert.That(reader.IsDBNull(0));
662+
if (Driver.CoreServerInfo.ServerVersion >= StorageProviderVersion.PostgreSql96) {
663+
if (part != SqlDateTimePart.Year) {
664+
Assert.That(reader.IsDBNull(0));
665+
}
666+
else {
667+
var partValue = reader.GetDouble(0);
668+
Assert.That(double.IsInfinity(partValue), Is.True);
669+
}
670+
}
640671
else {
641672
var partValue = reader.GetDouble(0);
642673
Assert.That(partValue, Is.Zero);
643674
}
644675
}
645-
if (Driver.CoreServerInfo.ServerVersion < StorageProviderVersion.PostgreSql96) {
646-
var partValue = reader.GetDouble(0);
647-
Assert.That(partValue, Is.Zero);
648-
}
649676
else {
677+
// pure dates
650678
var partValue = reader.GetDouble(0);
651679
CheckPartNative(partValue, expectedValueNative, aliasesEnabled);
652680
}
@@ -676,21 +704,26 @@ private void TestDateTimeOffsetPartExtraction(string table, SqlDateTimeOffsetPar
676704
using (var reader = command.ExecuteReader()) {
677705

678706
while (reader.Read()) {
679-
if (aliasesEnabled && part != SqlDateTimeOffsetPart.Year) {
680-
// year from +-infinity -> +-infinity
707+
if (aliasesEnabled) {
708+
// +-infinify
709+
// year from +-infinity -> +-infinity (or 0 in case of versions older than 9.6)
681710
// month from +-infinity -> null (or 0 in case of versions older that 9.6)
682-
if (Driver.CoreServerInfo.ServerVersion >= StorageProviderVersion.PostgreSql96 )
683-
Assert.That(reader.IsDBNull(0));
711+
if (Driver.CoreServerInfo.ServerVersion >= StorageProviderVersion.PostgreSql96) {
712+
if (part != SqlDateTimeOffsetPart.Year) {
713+
Assert.That(reader.IsDBNull(0));
714+
}
715+
else {
716+
var partValue = reader.GetDouble(0);
717+
Assert.That(double.IsInfinity(partValue), Is.True);
718+
}
719+
}
684720
else {
685721
var partValue = reader.GetDouble(0);
686722
Assert.That(partValue, Is.Zero);
687723
}
688724
}
689-
if (Driver.CoreServerInfo.ServerVersion < StorageProviderVersion.PostgreSql96) {
690-
var partValue = reader.GetDouble(0);
691-
Assert.That(partValue, Is.Zero);
692-
}
693725
else {
726+
// pure dates
694727
var partValue = reader.GetDouble(0);
695728
CheckPartNative(partValue, expectedValueNative, aliasesEnabled);
696729
}

0 commit comments

Comments
 (0)