1- // Copyright (C) 2010 Xtensive LLC.
2- // All rights reserved .
3- // For conditions of distribution and use, see license .
1+ // Copyright (C) 2010-2025 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: Denis Krjuchkov
55// Created: 2010.02.08
66
7+ using System . Data ;
78using NUnit . Framework ;
9+ using Xtensive . Sql ;
810
911namespace Xtensive . Orm . Tests . Sql . PostgreSql
1012{
1113 [ TestFixture ]
1214 public class ExceptionTypesTest : Sql . ExceptionTypesTest
1315 {
16+ private const string PgTimeoutTableName = "PgTheTimeout" ;
17+ private const string IdColumnName = "id" ;
18+
1419 protected override void CheckRequirements ( )
1520 {
1621 Require . ProviderIs ( StorageProvider . PostgreSql ) ;
1722 }
23+
24+ protected override void TestFixtureSetUp ( )
25+ {
26+ base . TestFixtureSetUp ( ) ;
27+ Connection . BeginTransaction ( ) ;
28+ EnsureTableNotExists ( schema , PgTimeoutTableName ) ;
29+ Connection . Commit ( ) ;
30+ }
31+
32+ [ Test ]
33+ public void PostgreSqlServerSideTimeout ( )
34+ {
35+ Connection . BeginTransaction ( ) ;
36+ var table = schema . CreateTable ( PgTimeoutTableName ) ;
37+ _ = CreatePrimaryKey ( table ) ;
38+ _ = ExecuteNonQuery ( SqlDdl . Create ( table ) ) ;
39+ Connection . Commit ( ) ;
40+
41+ var tableRef = SqlDml . TableRef ( table ) ;
42+ var insert = SqlDml . Insert ( tableRef ) ;
43+ insert . AddValueRow ( ( tableRef [ IdColumnName ] , 1 ) ) ;
44+
45+ using ( var connectionOne = Driver . CreateConnection ( ) ) {
46+ connectionOne . Open ( ) ;
47+ connectionOne . BeginTransaction ( ) ;
48+ using ( var command = connectionOne . CreateCommand ( ) ) {
49+ command . CommandText = "SET statement_timeout = 15" ;
50+ _ = command . ExecuteNonQuery ( ) ;
51+ }
52+
53+ using ( var connectionTwo = Driver . CreateConnection ( ) ) {
54+ connectionTwo . Open ( ) ;
55+ connectionTwo . BeginTransaction ( IsolationLevel . ReadCommitted ) ;
56+
57+ using ( var command = connectionTwo . CreateCommand ( insert ) ) {
58+ _ = command . ExecuteNonQuery ( ) ;
59+ }
60+ AssertExceptionType ( connectionOne , insert , SqlExceptionType . OperationTimeout ) ;
61+ }
62+ }
63+ }
1864 }
1965}
0 commit comments