public void SingletonReturnsSameValueWhenCalledInMultipleThreads()
        {
            StrategyChain strategies = GetStrategies();
            IPolicyList policies = GetPolicies();

            BuilderOnThread threadResults1 = new BuilderOnThread(strategies, policies);
            BuilderOnThread threadResults2 = new BuilderOnThread(strategies, policies);

            Task task1 = new Task(threadResults1.Build);
            Task task2 = new Task(threadResults2.Build);

            task1.Start();
            task2.Start();

            Task.WaitAll(task1, task2);

            Assert.AreSame(threadResults1.Result, threadResults2.Result);
        }
Exemple #2
0
        public void SingletonReturnsSameValueWhenCalledInMultipleThreads()
        {
            var         strategies = GetStrategies();
            IPolicyList policies   = GetPolicies();

            BuilderOnThread threadResults1 = new BuilderOnThread(strategies, policies);
            BuilderOnThread threadResults2 = new BuilderOnThread(strategies, policies);

            Task task1 = new Task(threadResults1.Build);
            Task task2 = new Task(threadResults2.Build);

            task1.Start();
            task2.Start();

            Task.WaitAll(task1, task2);

            Assert.AreSame(threadResults1.Result, threadResults2.Result);
        }
        public void SingletonReturnsSameValueWhenCalledInMultipleThreads()
        {
            StrategyChain strategies = GetStrategies();
            IPolicyList   policies   = GetPolicies();

            BuilderOnThread threadResults1 = new BuilderOnThread(strategies, policies);
            BuilderOnThread threadResults2 = new BuilderOnThread(strategies, policies);

            Thread thread1 = new Thread(new ThreadStart(threadResults1.Build));
            Thread thread2 = new Thread(new ThreadStart(threadResults2.Build));

            thread1.Start();
            thread2.Start();

            thread1.Join();
            thread2.Join();

            Assert.AreSame(threadResults1.Result, threadResults2.Result);
        }
        public void SingletonReturnsSameValueWhenCalledInMultipleThreads()
        {
            StrategyChain strategies = GetStrategies();
            IPolicyList policies = GetPolicies();

            BuilderOnThread threadResults1 = new BuilderOnThread(strategies, policies);
            BuilderOnThread threadResults2 = new BuilderOnThread(strategies, policies);

            Thread thread1 = new Thread(threadResults1.Build);
            Thread thread2 = new Thread(threadResults2.Build);

            thread1.Start();
            thread2.Start();

            thread1.Join();
            thread2.Join();

            Assert.AreSame(threadResults1.Result, threadResults2.Result);
        }