-
Notifications
You must be signed in to change notification settings - Fork 27
Issue: Cached query captures object in closure #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alex-kulakov
merged 7 commits into
DataObjects-NET:master
from
servicetitan:DelayedQueryCaptureTest
Mar 16, 2022
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
724d1be
Cached query captures object in closure
SergeiPavlov c2ad74b
Fix namespaces
SergeiPavlov 49f59b0
Rename namespace & class
SergeiPavlov 09d0352
Fix Issue 224
SergeiPavlov 645987d
Rename WellKnownTypes.IReadOnlyList -> .IReadOnlyListOfT
SergeiPavlov 51f7203
Rename IsSimpleType
SergeiPavlov ba7648e
Use TypeHelper.IsClosure() in AllocateParameterAndReplacer()
SergeiPavlov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Orm/Xtensive.Orm.Tests/Issues/IssueGithub0224_DelayedQueryCapture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (C) 2022 Xtensive LLC. | ||
// This code is distributed under MIT license terms. | ||
// See the License.txt file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Linq.Dynamic; | ||
using System.Reflection; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using Xtensive.Caching; | ||
using Xtensive.Orm.Configuration; | ||
using Xtensive.Orm.Tests.Issues.IssueGithub0224_DelayedQueryCapture_Model; | ||
|
||
namespace Xtensive.Orm.Tests.Issues | ||
{ | ||
namespace IssueGithub0224_DelayedQueryCapture_Model | ||
{ | ||
[HierarchyRoot] | ||
class Item : Entity | ||
{ | ||
[Field, Key] | ||
public int Id { get; private set; } | ||
|
||
[Field] | ||
public int Tag { get; set; } | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class IssueGithub0224_DelayedQueryCapture : AutoBuildTest | ||
{ | ||
public class OtherService | ||
{ | ||
public static volatile int InstanceCount; | ||
|
||
public int N; | ||
|
||
public OtherService() | ||
{ | ||
Interlocked.Increment(ref InstanceCount); | ||
} | ||
|
||
~OtherService() | ||
{ | ||
Interlocked.Decrement(ref InstanceCount); | ||
} | ||
} | ||
|
||
|
||
protected override DomainConfiguration BuildConfiguration() | ||
{ | ||
var config = base.BuildConfiguration(); | ||
config.Types.Register(typeof(Item).Assembly, typeof(Item).Namespace); | ||
return config; | ||
} | ||
|
||
[Test] | ||
public void DelayedQueryCapture() | ||
{ | ||
using (var session = Domain.OpenSession()) | ||
using (var t = session.OpenTransaction()) { | ||
var item = new Item() { Tag = 10 }; | ||
DelayedQuery(session); | ||
t.Complete(); | ||
} | ||
GC.Collect(); | ||
Thread.Sleep(1000); | ||
GC.Collect(); | ||
Assert.AreEqual(0, OtherService.InstanceCount); | ||
} | ||
|
||
private void DelayedQuery(Session session) | ||
{ | ||
var ids = new[] { 1, 2 }; | ||
var otherService = new OtherService(); | ||
|
||
var items = session.Query.CreateDelayedQuery(q => | ||
from t in q.All<Item>() | ||
where t.Id.In(ids) | ||
select t).ToArray(); | ||
|
||
var bb1 = items | ||
.Select(a => new { | ||
a.Id, | ||
A = new { | ||
B = otherService.N == a.Id | ||
}, | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.