コード例 #1
0
ファイル: TestFramework.cs プロジェクト: guiltedom/donkirkby
        public static void RunOnce(MultithreadedTestCase testCase)
        {
            var type = testCase.GetType();

            MethodInfo[] methods =
                type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
            var        tasks            = new List <TaskInfo>();
            MethodInfo initializeMethod = null;
            MethodInfo finishMethod     = null;

            foreach (var method in methods)
            {
                if (method.IsDefined(typeof(TestThreadAttribute), true))
                {
                    tasks.Add(new TaskInfo(method, testCase));
                }
                if (method.IsDefined(typeof(InitializeAttribute), true))
                {
                    initializeMethod = method;
                }
                if (method.IsDefined(typeof(FinishAttribute), true))
                {
                    finishMethod = method;
                }
            }

            // Add one more task for the ticker thread
            tasks.Add(new TaskInfo(
                          type.GetMethod("RunTicker", BindingFlags.NonPublic | BindingFlags.Instance),
                          testCase));

            if (initializeMethod != null)
            {
                initializeMethod.Invoke(testCase, null);
            }

            foreach (var task in tasks)
            {
                task.BeginInvoke();
            }

            TaskInfo.WaitAll(tasks, 5000);

            // we want to start with the ticker task to see if it timed out.
            for (int index = tasks.Count - 1; index >= 0; index--)
            {
                tasks[index].EndInvoke();
            }

            if (finishMethod != null)
            {
                finishMethod.Invoke(testCase, null);
            }
        }
コード例 #2
0
ファイル: TestFramework.cs プロジェクト: guiltedom/donkirkby
 public TaskInfo(MethodInfo taskMethod, MultithreadedTestCase testCase)
 {
     this.testCase   = testCase;
     this.taskMethod = taskMethod;
 }