Skip to content

Commit cd14774

Browse files
committed
Changes tests to work with new QueryResult's behavior
1 parent e29a100 commit cd14774

4 files changed

Lines changed: 49 additions & 72 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task EnumerationOutsideTransactionTest()
3737
result = await session.Query.CreateDelayedQuery(q => q.All<Discepline>())
3838
.ExecuteAsync();
3939
}
40-
_ = result.ToList();
40+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
4141
}
4242
}
4343
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ public async Task EnumerationOutsideTransactionTest()
4040
result = await session.Query.CreateDelayedQuery(q => q.All<Discepline>())
4141
.ExecuteAsync();
4242
}
43-
// because of materialization of fetched results not because of check in DelayedQuery.MaterializeAsync()
44-
//result.ToList();
43+
4544
var ex = Assert.Throws<InvalidOperationException>(() => result.ToList());
4645
Assert.That(ex.Message,
47-
Is.EqualTo(Strings.ExActiveTransactionIsRequiredForThisOperationUseSessionOpenTransactionToOpenIt));
46+
Is.EqualTo(Strings.ExThisInstanceIsExpiredDueToTransactionBoundaries));
4847
}
4948
}
5049
}

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,11 @@ public async Task EnumerationOutsideSessionTest()
9292
QueryResult<Discepline> result;
9393
await using (var session = Domain.OpenSession(SessionConfiguration))
9494
using (var tx = GetTransactionScope(session)) {
95-
result =await session.Query.CreateDelayedQuery(q => q.All<Discepline>())
95+
result = await session.Query.CreateDelayedQuery(q => q.All<Discepline>())
9696
.ExecuteAsync();
9797
}
9898

99-
// we didn't get StorageException here because we cache results and close db reader so
100-
// we materialize cached tuples to entity states which needs a session.
101-
// But the session is disposed so we have an exeption
102-
103-
var ex = Assert.Throws<ObjectDisposedException>(() => result.ToList());
99+
var ex = Assert.Throws<InvalidOperationException>(() => result.ToList());
104100
}
105101

106102
[Test]
@@ -150,14 +146,7 @@ public async Task EnumerationInOuterTransactionAfterInnerRollbackTest()
150146
.ExecuteAsync();
151147
}
152148

153-
// this is tricky. we've read results in one transaction, rollbacked it
154-
// and materialize results in another thansaction, which is not cool
155-
// because the data which existed in the inner transaction may not exist in the outer
156-
// so we can get "ghost" data.
157-
158-
// some exception has to appear.
159-
var ex = Assert.Throws<StorageException>(() => result.ToList());
160-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
149+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
161150
}
162151
}
163152
}

Orm/Xtensive.Orm.Tests/Storage/QueryResultTest.cs

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,8 @@ public void EnumerationOutsideTransactionTest()
107107
using (var transaction = session.OpenTransaction()) {
108108
result = session.Query.Execute(q => q.All<Order>());
109109
}
110-
if (SupportsMars()) {
111-
var ex = Assert.Throws<StorageException>(() => result.ToList());
112-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
113-
}
114-
else {
115-
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
116-
}
110+
111+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
117112
}
118113
}
119114

@@ -125,13 +120,8 @@ public async Task EnumerationOutsideTransactionAsyncTest()
125120
using (var transaction = session.OpenTransaction()) {
126121
result = await session.Query.ExecuteAsync(q => q.All<Order>());
127122
}
128-
if (SupportsMars()) {
129-
var ex = Assert.Throws<StorageException>(() => result.ToList());
130-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
131-
}
132-
else {
133-
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
134-
}
123+
124+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
135125
}
136126
}
137127

@@ -165,13 +155,8 @@ public void EnumerationOutsideTransactionClientProfileTest()
165155
using (var transaction = session.OpenTransaction()) {
166156
result = session.Query.Execute(q => q.All<Order>());
167157
}
168-
if (SupportsMars()) {
169-
var ex = Assert.Throws<StorageException>(() => result.ToList());
170-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
171-
}
172-
else {
173-
_ = result.ToList();
174-
}
158+
159+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
175160
}
176161
}
177162

@@ -184,13 +169,8 @@ public async Task EnumerationOutsideTransactionClientProfileAsyncTest()
184169
using (var transaction = session.OpenTransaction()) {
185170
result = await session.Query.ExecuteAsync(q => q.All<Order>());
186171
}
187-
if (SupportsMars()) {
188-
var ex = Assert.Throws<StorageException>(() => result.ToList());
189-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
190-
}
191-
else {
192-
_ = result.ToList();
193-
}
172+
173+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
194174
}
195175
}
196176

@@ -202,13 +182,8 @@ public void EnumerationOutsideSessionTest()
202182
using (var transaction = session.OpenTransaction()) {
203183
result = session.Query.Execute(q => q.All<Order>());
204184
}
205-
if (SupportsMars()) {
206-
var ex = Assert.Throws<StorageException>(() => result.ToList());
207-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
208-
}
209-
else {
210-
var ex = Assert.Throws<ObjectDisposedException>(() => result.ToList());
211-
}
185+
186+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
212187
}
213188

214189
[Test]
@@ -220,13 +195,7 @@ public async Task EnumerationOutsideSessionAsyncTest()
220195
result = await session.Query.ExecuteAsync(q => q.All<Order>());
221196
}
222197

223-
if (SupportsMars()) {
224-
var ex = Assert.Throws<StorageException>(() => result.ToList());
225-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
226-
}
227-
else {
228-
var ex = Assert.Throws<ObjectDisposedException>(() => result.ToList());
229-
}
198+
_ = Assert.Throws<InvalidOperationException>(() => result.ToList());
230199
}
231200

232201
[Test]
@@ -321,29 +290,49 @@ public async Task EnumerationInInnerVoidTransactionAsyncTest()
321290
[Test]
322291
public void EnumerationInOuterTransactionAfterInnerRollbackTest()
323292
{
293+
// sql server does not pull results to memory in client library
294+
var directReader = StorageProviderInfo.Instance.CheckProviderIs(StorageProvider.SqlServer);
295+
324296
using (var session = Domain.OpenSession()) {
325297
QueryResult<Order> result;
326-
using (var outerTx = session.OpenTransaction()) {
327-
using (var innerTx = session.OpenTransaction(TransactionOpenMode.New)) {
328-
result = session.Query.Execute(q => q.All<Order>());
329-
}
330-
var ex = Assert.Throws<StorageException>(() => result.ToList());
331-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
298+
// no using intentionally
299+
var outerTx = session.OpenTransaction();
300+
var innerTx = session.OpenTransaction(TransactionOpenMode.New);
301+
302+
result = session.Query.Execute(q => q.All<Order>());
303+
304+
if (directReader) {
305+
_ = Assert.Throws<StorageException>(() => innerTx.Dispose());
306+
_ = Assert.Throws<StorageException>(() => outerTx.Dispose());
307+
}
308+
else {
309+
Assert.DoesNotThrow(() => innerTx.Dispose());
310+
Assert.DoesNotThrow(() => outerTx.Dispose());
332311
}
333312
}
334313
}
335314

336315
[Test]
337316
public async Task EnumerationInOuterTransactionAfterInnerRollbackAsyncTest()
338317
{
318+
// sql server does not pull results to memory in client library
319+
var directReader = StorageProviderInfo.Instance.CheckProviderIs(StorageProvider.SqlServer);
320+
339321
using (var session = Domain.OpenSession()) {
340322
QueryResult<Order> result;
341-
using (var outerTx = session.OpenTransaction()) {
342-
using (var innerTx = session.OpenTransaction(TransactionOpenMode.New)) {
343-
result = await session.Query.ExecuteAsync(q => q.All<Order>());
344-
}
345-
var ex = Assert.Throws<StorageException>(() => result.ToList());
346-
Assert.That(ex.InnerException, Is.TypeOf<InvalidOperationException>());
323+
// no using intentionally
324+
var outerTx = session.OpenTransaction();
325+
var innerTx = session.OpenTransaction(TransactionOpenMode.New);
326+
327+
result = await session.Query.ExecuteAsync(q => q.All<Order>());
328+
329+
if (directReader) {
330+
_ = Assert.Throws<StorageException>(() => innerTx.Dispose());
331+
_ = Assert.Throws<StorageException>(() => outerTx.Dispose());
332+
}
333+
else {
334+
Assert.DoesNotThrow(() => innerTx.Dispose());
335+
Assert.DoesNotThrow(() => outerTx.Dispose());
347336
}
348337
}
349338
}

0 commit comments

Comments
 (0)