More working tests.
[castle.git] / InversionOfControl / Castle.Windsor.Tests / Configuration2 / SynchronizationProblemTestCase.cs
blobbe234087c37967afd2eb54eff79f2176b0ed95a6
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Windsor.Tests.Configuration2
17 using System;
18 using System.IO;
19 using System.Threading;
20 using Castle.Windsor.Configuration.Interpreters;
21 using Castle.Windsor.Tests.Components;
22 using NUnit.Framework;
24 [TestFixture, Explicit]
25 public class SynchronizationProblemTestCase
27 private string dir = ConfigHelper.ResolveConfigPath("Configuration2/");
28 private WindsorContainer container;
29 private ManualResetEvent startEvent = new ManualResetEvent(false);
30 private ManualResetEvent stopEvent = new ManualResetEvent(false);
32 [SetUp]
33 public void Init()
35 string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir +
36 "synchtest_config.xml");
38 container = new WindsorContainer(new XmlInterpreter(file));
40 container.Resolve(typeof(ComponentWithConfigs));
43 [TearDown]
44 public void Terminate()
46 container.Dispose();
49 [Test]
50 public void ResolveWithConfigTest()
52 const int threadCount = 50;
54 Thread[] threads = new Thread[threadCount];
56 for (int i = 0; i < threadCount; i++)
58 threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal));
59 threads[i].Start();
62 startEvent.Set();
64 Thread.CurrentThread.Join(10 * 2000);
66 stopEvent.Set();
69 private void ExecuteMethodUntilSignal()
71 startEvent.WaitOne(int.MaxValue, false);
73 while (!stopEvent.WaitOne(1, false))
75 try
77 ComponentWithConfigs comp = (ComponentWithConfigs) container.Resolve(typeof(ComponentWithConfigs));
79 Assert.AreEqual(AppDomain.CurrentDomain.BaseDirectory, comp.Name);
80 Assert.AreEqual(90, comp.Port);
81 Assert.AreEqual(1, comp.Dict.Count);
83 catch(Exception ex)
85 Console.WriteLine(DateTime.Now.Ticks + " ---------------------------\r\n" + ex);