Skip to content

Commit 9c91e57

Browse files
author
maximv
committed
added test for #337
1 parent 494dfb0 commit 9c91e57

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using NUnit.Framework;
5+
6+
namespace DryIoc.IssuesTests
7+
{
8+
[TestFixture]
9+
public class GHIssue337_Singleton_is_created_twice
10+
{
11+
[Test]
12+
public void Test()
13+
{
14+
var container = new Container();
15+
container.Register<A>(Reuse.Singleton);
16+
17+
var ts = new Task[8];
18+
for (int i = 0; i < ts.Length; i++)
19+
{
20+
ts[i] = Task.Run(() => container.Resolve<A>());
21+
}
22+
23+
Task.WaitAll(ts);
24+
}
25+
26+
class A
27+
{
28+
public static int Counter;
29+
public A()
30+
{
31+
Thread.Sleep(100);
32+
Console.WriteLine(++Counter);
33+
}
34+
}
35+
36+
}
37+
}

0 commit comments

Comments
 (0)