[Adapdev-commits] Adapdev/src/Adapdev.UnitTest.Core Adapdev.UnitTest.Core.csproj,1.9,1.10 RunTestCom
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-23 03:00:54
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24316/src/Adapdev.UnitTest.Core Modified Files: Adapdev.UnitTest.Core.csproj RunTestCommand.cs RunTestFixtureCommand.cs RunTestIterationCommand.cs TestRunner.cs TestSuiteBuilder.cs TestUnit.cs TextFormatter.cs Log Message: Index: TestSuiteBuilder.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestSuiteBuilder.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TestSuiteBuilder.cs 16 Nov 2005 07:01:53 -0000 1.13 --- TestSuiteBuilder.cs 23 Nov 2005 03:00:42 -0000 1.14 *************** *** 213,216 **** --- 213,217 ---- this.ProcessMaxKAttribute(m, t); this.ProcessMinOperationsPerSecondAttribute(m, t); + this.ProcessTransactionAttribute(m, t); if(log.IsDebugEnabled) log.Debug("Test built: " + t.ToString()); *************** *** 347,350 **** --- 348,363 ---- } + public void ProcessTransactionAttribute(ICustomAttributeProvider m, Test t) + { + if (TypeHelper.HasCustomAttribute(m, typeof(Adapdev.UnitTest.TransactionAttribute))) + { + t.TransactionType = TransactionType.AutoCommit; + } + else if (TypeHelper.HasCustomAttribute(m, typeof(Adapdev.UnitTest.RollbackTransactionAttribute))) + { + t.TransactionType = TransactionType.AutoRollback; + } + } + public void ProcessTestSetUpAttribute(ICustomAttributeProvider mi, TestHelper t) { Index: TestUnit.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestUnit.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestUnit.cs 16 Nov 2005 07:01:53 -0000 1.4 --- TestUnit.cs 23 Nov 2005 03:00:42 -0000 1.5 *************** *** 48,51 **** --- 48,52 ---- protected int _maxK = 0; protected ArrayList _attributes = new ArrayList(); + protected TransactionType _transaction = TransactionType.None; public TestUnit() *************** *** 65,68 **** --- 66,75 ---- } + public TransactionType TransactionType + { + get{return this._transaction;} + set{this._transaction = value;} + } + public void AddAttribute(Attribute a) { Index: RunTestCommand.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/RunTestCommand.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunTestCommand.cs 16 Nov 2005 07:01:53 -0000 1.4 --- RunTestCommand.cs 23 Nov 2005 03:00:42 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Collections; using System.Diagnostics; using System.IO; *************** *** 7,10 **** --- 8,12 ---- using Adapdev.Diagnostics; using Adapdev.Threading; + using Adapdev.Threading; using log4net; *************** *** 29,32 **** --- 31,35 ---- private object o = null; private TestFixtureIteration _testFixtureIteration = null; + private readonly SmartThreadPool pool; public RunTestCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi) *************** *** 40,43 **** --- 43,57 ---- } + public RunTestCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi, SmartThreadPool pool) + { + this._dispatcher = dispatcher; + this._test = test; + this._testFixture = tf; + this.o = o; + this._testFixtureIteration = tfi; + this.pool = pool; + this._type = type; + } + public void Execute() { *************** *** 81,96 **** private void RunTestIteration(TestResult testResult, MethodInfo method) { ! if(this._testFixture.IsMultiThreaded) { ! using(ThreadPoolWait threadPool = new ThreadPoolWait()) ! { ! for (int i = 1; i <= _test.RepeatCount; i++) ! { ! RunTestIterationCommand command = new RunTestIterationCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration, method, i, testResult); ! threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); ! } ! threadPool.WaitOne(); } } else --- 95,131 ---- private void RunTestIteration(TestResult testResult, MethodInfo method) { ! if(this._testFixture.IsMultiThreaded && this.pool != null) { ! ArrayList threads = new ArrayList(); ! for (int i = 1; i <= _test.RepeatCount; i++) ! { ! RunTestIterationCommand command = new RunTestIterationCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration, method, i, testResult); ! Thread t = new Thread(new ThreadStart(command.Execute)); ! threads.Add(t); ! t.Start(); } + foreach(Thread t in threads) t.Join(); + + // try + // { + // ArrayList workitems = new ArrayList(); + // + // for (int i = 1; i <= _test.RepeatCount; i++) + // { + // RunTestIterationCommand command = new RunTestIterationCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration, method, i, testResult); + // workitems.Add(pool.QueueWorkItem(new WorkItemCallback(command.Execute))); + // } + // + // workitems.TrimToSize(); + // IWorkItemResult[] results = workitems.ToArray(typeof(IWorkItemResult)) as IWorkItemResult[]; + // + // SmartThreadPool.WaitAll(results, 15000, true); + // } + // catch(Exception ex) + // { + // Console.WriteLine(ex.Message); + // Console.WriteLine(ex.StackTrace); + // } } else Index: TestRunner.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestRunner.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TestRunner.cs 16 Nov 2005 07:01:53 -0000 1.12 --- TestRunner.cs 23 Nov 2005 03:00:42 -0000 1.13 *************** *** 100,103 **** --- 100,104 ---- public TestAssemblyResult[] Run(TestSuite ts) { + Thread.CurrentThread.ApartmentState = ApartmentState.MTA; this._mode = RunMode.Running; ArrayList al = new ArrayList(); Index: TextFormatter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TextFormatter.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TextFormatter.cs 16 Nov 2005 07:01:53 -0000 1.10 --- TextFormatter.cs 23 Nov 2005 03:00:42 -0000 1.11 *************** *** 83,89 **** if(!(tar.State == TestState.Ignore)) { foreach(AbstractTestIteration ati in tar.Iterations) { ! if(tar.Iterations.Count > 1) sb.Append(this.GetNesting(nesting) + "Iteration: " + ati.Iteration + "\r\n"); sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\r\n", tar.Name, tar.State); //sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "Time: {0}s\r\n", tar.GetTotalDuration()); --- 83,93 ---- if(!(tar.State == TestState.Ignore)) { + if(tar.Iterations.Count > 1) nesting += 1; foreach(AbstractTestIteration ati in tar.Iterations) { ! if(tar.Iterations.Count > 1) ! { ! sb.Append(this.GetNesting(nesting) + "Iteration: " + ati.Iteration + "\r\n"); ! } sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\r\n", tar.Name, tar.State); //sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "Time: {0}s\r\n", tar.GetTotalDuration()); *************** *** 93,96 **** --- 97,106 ---- } + if(ati is TestIteration) + { + sb.Append(this.GetNesting(nesting + 2) + "Thread Id: " + (ati as TestIteration).Thread + Environment.NewLine); + sb.Append(this.GetNesting(nesting + 2) + "Time: " + (ati as TestIteration).Duration + Environment.NewLine); + } + if(showFailure && (ati is TestIteration)) { *************** *** 100,108 **** } - if(ati is TestIteration) - { - sb.Append(this.GetNesting(nesting + 2) + "Thread Id: " + (ati as TestIteration).Thread + Environment.NewLine); - sb.Append(this.GetNesting(nesting + 2) + "Time: " + (ati as TestIteration).Duration + Environment.NewLine); - } if(showOutput && ati.ConsoleOutput.Length > 0) --- 110,113 ---- Index: RunTestIterationCommand.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/RunTestIterationCommand.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunTestIterationCommand.cs 16 Nov 2005 07:01:53 -0000 1.5 --- RunTestIterationCommand.cs 23 Nov 2005 03:00:42 -0000 1.6 *************** *** 4,7 **** --- 4,8 ---- using System.Reflection; using System.Threading; + using Adapdev.Commands; using Adapdev.Diagnostics; *************** *** 11,15 **** /// Summary description for RunTestIterationCommand. /// </summary> ! public class RunTestIterationCommand { private TestEventDispatcher _dispatcher = null; --- 12,16 ---- /// Summary description for RunTestIterationCommand. /// </summary> ! public class RunTestIterationCommand : IThreadWorkItemCommand { private TestEventDispatcher _dispatcher = null; *************** *** 72,77 **** kStart = Process.GetCurrentProcess().WorkingSet; timer.Start(); ! ! new RunMethodCommand(this._method, o).Execute(); timer.Stop(); --- 73,83 ---- kStart = Process.GetCurrentProcess().WorkingSet; timer.Start(); ! ! // Check for transactions and run ! ICommand command = new RunMethodCommand(this._method, o); ! if(this._test.TransactionType == TransactionType.AutoCommit) command = new AutoCommitCommand(command); ! else if(this._test.TransactionType == TransactionType.AutoRollback) command = new AutoRollbackCommand(command); ! command.Execute(); ! timer.Stop(); *************** *** 230,234 **** ! public void Execute(object o){this.Execute();} } } --- 236,240 ---- ! public object Execute(object o){this.Execute();return 1;} } } Index: RunTestFixtureCommand.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/RunTestFixtureCommand.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunTestFixtureCommand.cs 16 Nov 2005 07:01:53 -0000 1.4 --- RunTestFixtureCommand.cs 23 Nov 2005 03:00:42 -0000 1.5 *************** *** 11,15 **** /// Summary description for TestFixtureCommand. /// </summary> ! public class RunTestFixtureCommand : ICommand { private TestEventDispatcher _dispatcher = null; --- 11,15 ---- /// Summary description for TestFixtureCommand. /// </summary> ! public class RunTestFixtureCommand : IThreadWorkItemCommand { private TestEventDispatcher _dispatcher = null; *************** *** 96,108 **** if(this._testFixture.IsMultiThreaded) { ! using(ThreadPoolWait threadPool = new ThreadPoolWait()) { ! foreach (Test test in this._testFixture.GetTests()) ! { ! RunTestCommand command = new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); ! threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); ! } ! threadPool.WaitOne(); } } else --- 96,146 ---- if(this._testFixture.IsMultiThreaded) { ! ArrayList threads = new ArrayList(); ! ! foreach (Test test in this._testFixture.GetTests()) { ! RunTestCommand command = new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); ! Thread t = new Thread(new ThreadStart(command.Execute)); ! threads.Add(t); ! t.Start(); } + foreach(Thread t in threads) t.Join(); + + + // using(ThreadPoolWait threadPool = new ThreadPoolWait()) + // { + // foreach (Test test in this._testFixture.GetTests()) + // { + // RunTestCommand command = new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); + // threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); + // } + // threadPool.WaitOne(); + // } + + // SmartThreadPool smartThreadPool = new SmartThreadPool(); + // + // try + // { + // ArrayList workitems = new ArrayList(); + // + // foreach(Test test in this._testFixture.GetTests()) + // { + // RunTestCommand command = new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); + // workitems.Add(smartThreadPool.QueueWorkItem(new WorkItemCallback(command.Execute))); + // } + // + // workitems.TrimToSize(); + // IWorkItemResult[] results = workitems.ToArray(typeof(IWorkItemResult)) as IWorkItemResult[]; + // SmartThreadPool.WaitAll(results, 15000, true); + // } + // catch(Exception ex) + // { + // Console.WriteLine(ex.Message); + // Console.WriteLine(ex.StackTrace); + // } + // finally + // { + // smartThreadPool.Shutdown(); + // } } else *************** *** 115,118 **** --- 153,161 ---- } + public object Execute(object o) + { + this.Execute(); + return 1; + } } } Index: Adapdev.UnitTest.Core.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/Adapdev.UnitTest.Core.csproj,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Adapdev.UnitTest.Core.csproj 16 Nov 2005 07:01:53 -0000 1.9 --- Adapdev.UnitTest.Core.csproj 23 Nov 2005 03:00:42 -0000 1.10 *************** *** 142,145 **** --- 142,155 ---- /> <File + RelPath = "AutoCommitCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "AutoRollbackCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "BaseTestHelper.cs" SubType = "Code" *************** *** 167,170 **** --- 177,185 ---- /> <File + RelPath = "IThreadWorkItemCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "LocalSeparateTestEngine.cs" SubType = "Code" |