Add tests for registering and resolving accross threads

This commit is contained in:
Mike Bierlee 2015-03-28 18:01:16 +01:00
parent ee88b68a7c
commit 24e9a67219

View file

@ -8,6 +8,7 @@
import poodinis.container; import poodinis.container;
import std.exception; import std.exception;
import core.thread;
version(unittest) { version(unittest) {
interface TestInterface { interface TestInterface {
@ -394,4 +395,35 @@ version(unittest) {
assert(john.wants.moolah !is null, "Autowire stack did not clear entries properly"); assert(john.wants.moolah !is null, "Autowire stack did not clear entries properly");
} }
// Test resolving registration registered in different thread
unittest {
shared(DependencyContainer) container = new DependencyContainer();
auto thread = new Thread(delegate() {
container.register!TestClass;
});
thread.start();
thread.join();
container.resolve!TestClass;
}
// Test resolving instance previously resolved in different thread
unittest {
shared(DependencyContainer) container = new DependencyContainer();
shared(TestClass) actualTestClass;
container.register!TestClass;
auto thread = new Thread(delegate() {
actualTestClass = cast(shared(TestClass)) container.resolve!TestClass;
});
thread.start();
thread.join();
shared(TestClass) expectedTestClass = cast(shared(TestClass)) container.resolve!TestClass;
assert(expectedTestClass is actualTestClass, "Instance resolved in main thread is not the one resolved in thread");
}
} }