mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add tests for registering and resolving accross threads
This commit is contained in:
parent
ee88b68a7c
commit
24e9a67219
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue