Skip to content

Commit 12e2de9

Browse files
committed
Some tests fixed for Postgres
- Spatial test now expects right value for PgsqlPath (new client library writes to db correct default falue for PgsqlPath.Open) - float accuracy is taken into account for Sum and Average results - Removed Postgres from list of test storages for some test method (see comment in Require) - Rounding test uses special Entities for decimans and doubles - some sabbath word wierdness workarounded
1 parent c8cae25 commit 12e2de9

7 files changed

Lines changed: 102 additions & 56 deletions

File tree

Orm/Xtensive.Orm.Tests/Issues/IssueJira0593_AggregateForSingleColumnTest.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public class IssueJira0593_AggregateForSingleColumnTest : AutoBuildTest
118118
private const int EntityCount = 20;
119119
private const string FilterCondition = "3";
120120

121+
private const decimal FloatValueAccuracy = 0.00001m;
122+
121123
protected override DomainConfiguration BuildConfiguration()
122124
{
123125
var config = base.BuildConfiguration();
@@ -584,10 +586,15 @@ private static void CheckQueryable(IQueryable<long?> query)
584586
private static void CheckQueryable(IQueryable<float> query)
585587
{
586588
var localArray = query.ToArray();
587-
Assert.AreEqual(localArray.Sum(), query.Sum(c => c));
588-
Assert.AreEqual(localArray.Sum(), query.Sum());
589-
Assert.AreEqual(localArray.Average(), query.Average(c => c));
590-
Assert.AreEqual(localArray.Average(), query.Average());
589+
Assert.That(Math.Abs(query.Sum(c => c) - localArray.Sum()), Is.LessThan(FloatValueAccuracy));
590+
Assert.That(Math.Abs(query.Sum() - localArray.Sum()), Is.LessThan(FloatValueAccuracy));
591+
//Assert.AreEqual(localArray.Sum(), query.Sum(c => c));
592+
//Assert.AreEqual(localArray.Sum(), query.Sum());
593+
594+
Assert.That(Math.Abs(query.Average(c => c) - localArray.Average()), Is.LessThan(FloatValueAccuracy));
595+
Assert.That(Math.Abs(query.Average() - localArray.Average()), Is.LessThan(FloatValueAccuracy));
596+
//Assert.AreEqual(localArray.Average(), query.Average(c => c));
597+
//Assert.AreEqual(localArray.Average(), query.Average());
591598
Assert.AreEqual(localArray.Min(), query.Min(c => c));
592599
Assert.AreEqual(localArray.Min(), query.Min());
593600
Assert.AreEqual(localArray.Max(), query.Max(c => c));
@@ -598,10 +605,15 @@ private static void CheckQueryable(IQueryable<float> query)
598605
private static void CheckQueryable(IQueryable<float?> query)
599606
{
600607
var localArray = query.ToArray();
601-
Assert.AreEqual(localArray.Sum(), query.Sum(c => c));
602-
Assert.AreEqual(localArray.Sum(), query.Sum());
603-
Assert.AreEqual(localArray.Average(), query.Average(c => c));
604-
Assert.AreEqual(localArray.Average(), query.Average());
608+
609+
Assert.That(Math.Abs(query.Sum(c => c).Value - localArray.Sum().Value), Is.LessThan(FloatValueAccuracy));
610+
Assert.That(Math.Abs(query.Sum().Value - localArray.Sum().Value), Is.LessThan(FloatValueAccuracy));
611+
//Assert.AreEqual(localArray.Sum(), query.Sum(c => c));
612+
//Assert.AreEqual(localArray.Sum(), query.Sum());
613+
Assert.That(Math.Abs(query.Average(c => c).Value - localArray.Average().Value), Is.LessThan(FloatValueAccuracy));
614+
Assert.That(Math.Abs(query.Average().Value - localArray.Average().Value), Is.LessThan(FloatValueAccuracy));
615+
//Assert.AreEqual(localArray.Average(), query.Average(c => c));
616+
//Assert.AreEqual(localArray.Average(), query.Average());
605617
Assert.AreEqual(localArray.Min(), query.Min(c => c));
606618
Assert.AreEqual(localArray.Min(), query.Min());
607619
Assert.AreEqual(localArray.Max(), query.Max(c => c));

Orm/Xtensive.Orm.Tests/Linq/FreeTextTest.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexis Kochetov
55
// Created: 2009.12.14
66

@@ -365,7 +365,16 @@ where ft.Entity.TrackId > 0 && ft.Entity.UnitPrice > 0.8m
365365
orderby ft.Entity.Album.Title, ft.Entity.UnitPrice
366366
select new {Track = ft.Entity, ft.Entity.Name};
367367
var list = result.ToList();
368-
Assert.AreEqual(26, list.Count);
368+
369+
if (StorageProviderInfo.Instance.CheckProviderIs(StorageProvider.PostgreSql)) {
370+
// for some reason PosgreSQL does not like the 'sabbath' word.
371+
// there are two tracks with this word in name and they are missing in results.
372+
// direct search by the word also does not show any of these two tracks.
373+
Assert.AreEqual(24, list.Count);
374+
}
375+
else {
376+
Assert.AreEqual(26, list.Count);
377+
}
369378
}
370379

371380
[Test]

Orm/Xtensive.Orm.Tests/Storage/AsyncQueries/PersistWithAsyncQueriesTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public async Task AsyncButFullySequentialTest()
103103
[Test]
104104
public async Task QueryFirstWaitLaterTest()
105105
{
106+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands, so having two readers opened is impossible");
106107
using (var session = Domain.OpenSession())
107108
using (var transaction = session.OpenTransaction()) {
108109
var readyToRockQuery = session.Query.All<TestEntity>().AsAsync();
@@ -128,6 +129,7 @@ public async Task QueryFirstWaitLaterTest()
128129
[Test]
129130
public async Task QueryFirstWaitLaterInDiffferentOrderTest()
130131
{
132+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands. so having opened reader for query and making changes saved is impossible");
131133
using (var session = Domain.OpenSession())
132134
using (var transaction = session.OpenTransaction()){
133135
var readyToRockQuery = session.Query.All<TestEntity>().AsAsync();
@@ -216,6 +218,7 @@ public async Task ProperPersistSequenceFirebirdTest()
216218
[Test]
217219
public async Task PersistBeforeFirstAsyncQueryAwaitTest()
218220
{
221+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands. so having two readers opened is impossible");
219222
using (var session = Domain.OpenSession())
220223
using (var transaction = session.OpenTransaction()) {
221224
_ = new TestEntity(session);
@@ -244,6 +247,7 @@ public async Task PersistBeforeFirstAsyncQueryAwaitTest()
244247
public async Task PersistBeforeSecondAsyncQueryAwaitTest()
245248
{
246249
Require.ProviderIsNot(StorageProvider.Firebird, "Open reader reads lines that were inserted between getting reader and enumeratin it");
250+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands, so having opened reader for query and making changes saved is impossible");
247251
using (var session = Domain.OpenSession())
248252
using (var transaction = session.OpenTransaction()) {
249253
var readyToRockQuery = await session.Query.All<TestEntity>().AsAsync();
@@ -300,6 +304,7 @@ public async Task PersistBeforeSecondAsyncQueryAwaitFirebirdTest()
300304
public async Task PersistBeforeBothAsyncQueriesAndDelayedWaitTest()
301305
{
302306
Require.ProviderIsNot(StorageProvider.Firebird, "Open reader reads lines that were inserted between getting reader and enumeratin it");
307+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands, so having opened reader for query and making changes saved is impossible");
303308
using (var session = Domain.OpenSession())
304309
using (var transaction = session.OpenTransaction()) {
305310
_ = new TestEntity(session) { Value = 101 };
@@ -363,6 +368,7 @@ public async Task PersistBeforeBothAsyncQueriesAndDelayedWaitFirebirdTest()
363368
[Test]
364369
public async Task PersistBeforeFirstAsyncQueryAndDalayedAwaitTest()
365370
{
371+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands, so having two readers opened is impossible");
366372
using (var session = Domain.OpenSession())
367373
using (var transaction = session.OpenTransaction()) {
368374
_ = new TestEntity(session);
@@ -391,6 +397,7 @@ public async Task PersistBeforeFirstAsyncQueryAndDalayedAwaitTest()
391397
public async Task PersistBeforeSecondAsyncQueryAndDelayedAwaitTest()
392398
{
393399
Require.ProviderIsNot(StorageProvider.Firebird, "Open reader reads lines that were inserted between getting reader and enumeratin it");
400+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands. so having opened reader for query and making changes saved is impossible");
394401
using (var session = Domain.OpenSession())
395402
using (var transaction = session.OpenTransaction()) {
396403
var readyToRockQuery = session.Query.All<TestEntity>().AsAsync();
@@ -504,6 +511,7 @@ public async Task AwaitingQueryBeforeManualSavingChangesTest()
504511
public async Task ManualSavingDuringAsyncQueryExecutionTest()
505512
{
506513
Require.ProviderIsNot(StorageProvider.Firebird, "Open reader reads lines that were inserted between getting reader and enumeratin it");
514+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands. so having opened reader for query and making changes saved is impossible");
507515
using (var session = Domain.OpenSession())
508516
using (var transaction = session.OpenTransaction()) {
509517
_ = new TestEntity(session);
@@ -562,6 +570,7 @@ public async Task ManualSavingDuringAsyncQueryExecutionFirebirdTest()
562570
[Test]
563571
public async Task ManualSavingDuringEnumerationTest()
564572
{
573+
Require.ProviderIsNot(StorageProvider.PostgreSql, "No parallel executing for commands. so having opened reader for query and making changes saved is impossible");
565574
using (var session = Domain.OpenSession())
566575
using (var transaction = session.OpenTransaction()) {
567576
var readyToRockQuery = session.Query.All<TestEntity>().AsAsync();

Orm/Xtensive.Orm.Tests/Storage/NewProfilesTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C) 2014-2021 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2014.04.14
66

@@ -850,6 +850,8 @@ public void ClientProfileSameExceptionWhenDoublePersist()
850850
[Test]
851851
public void ClientProfileSameExceptionWhenDoublePersistInsideTransaction()
852852
{
853+
Require.ProviderIsNot(StorageProvider.PostgreSql, "UniqueVauleConstraint breaks the outermost transaction.");
854+
853855
using (var session = Domain.OpenSession(clientProfile)) {
854856
using (var transaction = session.OpenTransaction()) {
855857
var authorWithUniqueName = new Author {Name = "Peter"};

Orm/Xtensive.Orm.Tests/Storage/PostgreSqlSpatialTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2011 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2014-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alena Mikshina
55
// Created: 2014.04.09
66

@@ -67,7 +67,7 @@ public void MainTest()
6767

6868
using (Domain.OpenSession()) {
6969
using (var t = Session.Current.OpenTransaction()) {
70-
new Container {
70+
_ = new Container {
7171
Point = new NpgsqlPoint(),
7272
LSeg = new NpgsqlLSeg(),
7373
Box = new NpgsqlBox(),
@@ -76,7 +76,7 @@ public void MainTest()
7676
Circle = new NpgsqlCircle()
7777
};
7878

79-
new Container {
79+
_ = new Container {
8080
Point = point,
8181
LSeg = lSeg,
8282
Box = box,
@@ -96,7 +96,7 @@ public void MainTest()
9696
Assert.IsTrue(record.Point.Equals(new NpgsqlPoint()));
9797
Assert.IsTrue(record.LSeg.Equals(new NpgsqlLSeg()));
9898
Assert.IsTrue(record.Box.Equals(new NpgsqlBox()));
99-
Assert.IsTrue(record.Path.Equals(new NpgsqlPath(new[] {new NpgsqlPoint()}) {Open = true}));
99+
Assert.IsTrue(record.Path.Equals(new NpgsqlPath(new[] {new NpgsqlPoint()})));
100100
Assert.IsTrue(record.Polygon.Equals(new NpgsqlPolygon(new[] {new NpgsqlPoint()})));
101101
Assert.IsTrue(record.Circle.Equals(new NpgsqlCircle()));
102102

0 commit comments

Comments
 (0)