Skip to content

Commit 1166bee

Browse files
committed
Improved some tests of Extesions' projects
1 parent 6016920 commit 1166bee

4 files changed

Lines changed: 35 additions & 36 deletions

File tree

Extensions/Xtensive.Orm.Localization.Tests/AccessToLocalizationOnUpgrade.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public void TestFixtureSetup()
3434
{
3535
var configuration = DomainConfigurationFactory.Create();
3636
configuration.Types.Register(typeof(ILocalizable<>).Assembly);
37-
configuration.Types.Register(typeof(LocalizationBaseTest).Assembly, typeof(LocalizationBaseTest).Namespace);
37+
configuration.Types.Register(typeof(Page).Assembly, typeof(Page).Namespace);
38+
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
3839

3940
using (var domain = Domain.Build(configuration))
4041
using (var session = domain.OpenSession())
@@ -55,7 +56,7 @@ public void MainTest()
5556
{
5657
var configuration = DomainConfigurationFactory.Create();
5758
configuration.Types.Register(typeof (ILocalizable<>).Assembly);
58-
configuration.Types.Register(typeof (LocalizationBaseTest).Assembly, typeof (LocalizationBaseTest).Namespace);
59+
configuration.Types.Register(typeof (Page).Assembly, typeof (Page).Namespace);
5960
configuration.Types.Register(typeof (CustomUpgradeHandler));
6061
configuration.UpgradeMode = DomainUpgradeMode.PerformSafely;
6162

Extensions/Xtensive.Orm.Localization.Tests/LocalizationBaseTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NUnit.Framework;
33
using Xtensive.Orm.Configuration;
44
using Xtensive.Orm.Tests;
5+
using Xtensive.Orm.Localization.Tests.Model;
56

67
namespace Xtensive.Orm.Localization.Tests
78
{
@@ -12,7 +13,7 @@ protected override DomainConfiguration BuildConfiguration()
1213
{
1314
var configuration = base.BuildConfiguration();
1415
configuration.Types.Register(typeof(ILocalizable<>).Assembly);
15-
configuration.Types.Register(typeof(LocalizationBaseTest).Assembly, typeof(LocalizationBaseTest).Namespace);
16+
configuration.Types.Register(typeof(Page).Assembly, typeof(Page).Namespace);
1617
return configuration;
1718
}
1819
}

Extensions/Xtensive.Orm.Localization.Tests/MultipleNodesTest.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ public class MultipleNodesTest : CommonModelTest
2828
private const string ThridNodeSchema = WellKnownSchemas.Schema4;
2929
private const string ForthNodeSchema = WellKnownSchemas.Schema5;
3030

31-
//private static readonly CultureInfo English.Culture = new CultureInfo("en-US");
32-
//private static readonly string English.Title = "Welcome!";
33-
//private static readonly string English.Content = "My dear guests, welcome to my birthday party!";
34-
35-
//private static readonly CultureInfo Spanish.Culture = new CultureInfo("es-ES");
36-
//private static readonly string Spanish.Title = "Bienvenido!";
37-
//private static readonly string Spanish.Content = "Mis amigos mejores! Bienvenido a mi cumpleanos!";
38-
3931
protected override void CheckRequirements() =>
4032
Require.AllFeaturesSupported(Providers.ProviderFeatures.Multischema);
4133

@@ -52,7 +44,7 @@ protected override DomainConfiguration BuildConfiguration()
5244
{
5345
var configuration = base.BuildConfiguration();
5446
configuration.Types.Register(typeof(ILocalizable<>).Assembly);
55-
configuration.Types.Register(typeof(LocalizationBaseTest).Assembly, typeof(LocalizationBaseTest).Namespace);
47+
configuration.Types.Register(typeof(Page).Assembly, typeof(Page).Namespace);
5648
configuration.DefaultSchema = DefaultNodeSchema;
5749
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
5850
return configuration;

Extensions/Xtensive.Orm.Reprocessing.Tests/Tests/Context.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace Xtensive.Orm.Reprocessing.Tests.ReprocessingContext
1515
public class Context : IDisposable
1616
{
1717
private readonly Domain domain;
18+
private readonly AutoResetEvent wait1 = new AutoResetEvent(false);
19+
private readonly AutoResetEvent wait2 = new AutoResetEvent(false);
1820

1921
public int Count;
20-
private AutoResetEvent wait1 = new AutoResetEvent(false);
21-
private AutoResetEvent wait2 = new AutoResetEvent(false);
22-
22+
2323
public bool Disposed { get; private set; }
2424

2525
/// <summary>
@@ -52,6 +52,9 @@ public void Run(
5252

5353
public void Deadlock(bool first, IsolationLevel? isolationLevel, TransactionOpenMode? transactionOpenMode)
5454
{
55+
int firstRunsCount = 0;
56+
int secondRunsCount = 0;
57+
5558
domain.WithStrategy(ExecuteActionStrategy.HandleUniqueConstraintViolation)
5659
.WithIsolationLevel(isolationLevel.GetValueOrDefault(IsolationLevel.RepeatableRead))
5760
.WithTransactionOpenMode(transactionOpenMode.GetValueOrDefault(TransactionOpenMode.New))
@@ -60,21 +63,19 @@ public void Deadlock(bool first, IsolationLevel? isolationLevel, TransactionOpen
6063
_ = new Bar2(session, DateTime.Now, Guid.NewGuid()) { Name = Guid.NewGuid().ToString() };
6164
if (first) {
6265
_ = session.Query.All<Foo>().Lock(LockMode.Exclusive, LockBehavior.Wait).ToArray();
63-
if (wait1 != null) {
66+
if (firstRunsCount == 0) {
6467
_ = wait1.Set();
6568
_ = wait2.WaitOne();
66-
wait1.Dispose();
67-
wait1 = null;
69+
_ = Interlocked.Increment(ref firstRunsCount);
6870
}
6971
_ = session.Query.All<Bar>().Lock(LockMode.Exclusive, LockBehavior.Wait).ToArray();
7072
}
7173
else {
7274
_ = session.Query.All<Bar>().Lock(LockMode.Exclusive, LockBehavior.Wait).ToArray();
73-
if (wait2 != null) {
75+
if (secondRunsCount == 0) {
7476
_ = wait2.Set();
7577
_ = wait1.WaitOne();
76-
wait2.Dispose();
77-
wait2 = null;
78+
_ = Interlocked.Increment(ref secondRunsCount);
7879
}
7980
_ = session.Query.All<Foo>().Lock(LockMode.Exclusive, LockBehavior.Wait).ToArray();
8081
}
@@ -171,6 +172,9 @@ public void Parent(
171172
public void UniqueConstraintViolation(
172173
bool first, IsolationLevel? isolationLevel, TransactionOpenMode? transactionOpenMode)
173174
{
175+
int firstRunsCount = 0;
176+
int secondRunsCount = 0;
177+
174178
domain.WithStrategy(ExecuteActionStrategy.HandleUniqueConstraintViolation)
175179
.WithIsolationLevel(isolationLevel.GetValueOrDefault(IsolationLevel.RepeatableRead))
176180
.WithTransactionOpenMode(transactionOpenMode.GetValueOrDefault(TransactionOpenMode.New))
@@ -180,21 +184,22 @@ public void UniqueConstraintViolation(
180184
_ = new Bar2(session, DateTime.Now, Guid.NewGuid()) { Name = Guid.NewGuid().ToString() };
181185
var name = "test";
182186
if (!session.Query.All<Foo>().Any(a => a.Name == name)) {
187+
var w1 = wait1;
188+
var w2 = wait2;
183189
if (first) {
184-
if (wait1 != null && wait2 != null) {
185-
_ = wait1.Set();
186-
_ = wait2.WaitOne();
187-
wait1.Dispose();
188-
wait1 = null;
190+
if (w1 != null && w2 != null) {
191+
_ = w1.Set();
192+
_ = w2.WaitOne();
193+
//wait1.Dispose();
194+
w1 = null;
189195
}
190196
}
191-
else if (wait2 != null && wait2 != null) {
192-
_ = wait2.Set();
193-
_ = wait1.WaitOne();
194-
wait2.Dispose();
195-
wait2 = null;
197+
else if (w2 != null && w2 != null) {
198+
_ = w2.Set();
199+
_ = w1.WaitOne();
200+
//wait2.Dispose();
201+
w2 = null;
196202
}
197-
_ = new Foo(session) { Name = name };
198203
}
199204
session.SaveChanges();
200205
});
@@ -218,15 +223,15 @@ public void UniqueConstraintViolationPrimaryKey(
218223
if (w1 != null && w2 != null) {
219224
_ = w1.Set();
220225
_ = w2.WaitOne();
221-
wait1.Dispose();
222-
wait1 = null;
226+
//wait1.Dispose();
227+
w1 = null;
223228
}
224229
}
225230
else if (w1 != null && w2 != null) {
226231
_ = w2.Set();
227232
_ = w1.WaitOne();
228-
wait2.Dispose();
229-
wait2 = null;
233+
//wait2.Dispose();
234+
w2 = null;
230235
}
231236
_ = new Foo(session, id) { Name = Guid.NewGuid().ToString() };
232237
}

0 commit comments

Comments
 (0)