Skip to content

Commit cd5c1ff

Browse files
committed
added the failing test for the #391
1 parent 75f69af commit cd5c1ff

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using NUnit.Framework;
2+
using System.Threading.Tasks;
3+
4+
namespace DryIoc.IssuesTests
5+
{
6+
[TestFixture]
7+
public class GHIssue391_Deadlock_during_Resolve : ITest
8+
{
9+
public int Run()
10+
{
11+
Test1();
12+
return 1;
13+
}
14+
15+
[Test][Ignore("fixme")]
16+
public void Test1()
17+
{
18+
var container = new Container(rules => rules
19+
.With(FactoryMethod.ConstructorWithResolvableArguments)
20+
.WithoutEagerCachingSingletonForFasterAccess()
21+
.WithoutThrowOnRegisteringDisposableTransient()
22+
.WithDefaultIfAlreadyRegistered(IfAlreadyRegistered.Replace));
23+
24+
container.Register(typeof(A), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
25+
container.RegisterMany(new [] { typeof(A), typeof(IA) }, typeof(A), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
26+
27+
container.Register(typeof(B), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
28+
container.RegisterMany(new [] { typeof(B), typeof(IB) }, typeof(B), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
29+
30+
container.Register(typeof(C), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
31+
container.RegisterMany(new [] { typeof(C), typeof(IC) }, typeof(C), Reuse.Singleton, setup: Setup.With(asResolutionCall: true));
32+
33+
// the missing dependency
34+
// container.Register<ID, D>(Reuse.Singleton);
35+
36+
Assert.Throws<ContainerException>(() => container.Resolve<IA>());
37+
38+
// the second code deadlocks instead of throwing
39+
Assert.Throws<ContainerException>(() => container.Resolve<IA>());
40+
}
41+
42+
// A -> B -> C -> D(missing)
43+
// \----->
44+
45+
public interface IA {}
46+
public interface IB {}
47+
public interface IC {}
48+
public interface ID {}
49+
50+
public class A : IA
51+
{
52+
private IB B;
53+
private IC C;
54+
public A(IC c,IB b)
55+
{
56+
B = b;
57+
C = c;
58+
}
59+
}
60+
61+
public class B : IB
62+
{
63+
private IC C;
64+
public B(IC c) => C = c;
65+
}
66+
67+
public class C : IC
68+
{
69+
private ID D;
70+
public C(ID d) => D = d;
71+
}
72+
73+
public class D : ID {}
74+
}
75+
}

0 commit comments

Comments
 (0)