Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ActiveTestSuite.cs « NUnitCore « src « nunit « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 605911d233c7dc9a36b9fc421263289d4ab9efd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
namespace NUnit.Extensions {
    
  using System;
  using System.Threading;
  
  using NUnit.Framework;
  
  /// <summary>A TestSuite for active Tests. It runs each
  /// test in a separate thread and until all
  /// threads have terminated.
  /// -- Aarhus Radisson Scandinavian Center 11th floor</summary>
  public class ActiveTestSuite: TestSuite {
    private int fActiveTestDeathCount;
	/// <summary>
	/// 
	/// </summary>
	/// <param name="result"></param>
    public override void Run(TestResult result) {
      fActiveTestDeathCount= 0;
      base.Run(result);
      WaitUntilFinished();
    }
    /// <summary>
    /// 
    /// </summary>
    public class ThreadLittleHelper {
      private ITest fTest;
      private TestResult fResult;
      private ActiveTestSuite fSuite;
		/// <summary>
		/// 
		/// </summary>
		/// <param name="test"></param>
		/// <param name="result"></param>
		/// <param name="suite"></param>
      public ThreadLittleHelper(ITest test, TestResult result,
                                ActiveTestSuite suite) {
        fSuite = suite;
        fTest = test;
        fResult = result;
      }
	/// <summary>
	/// 
	/// </summary>
      public void Run() {
        try {
          fSuite.BaseRunTest(fTest, fResult);
        } finally {
          fSuite.RunFinished(fTest);
        }
      }
    }
  /// <summary>
  /// 
  /// </summary>
  /// <param name="test"></param>
  /// <param name="result"></param>
    public void BaseRunTest(ITest test, TestResult result) {
      base.RunTest(test, result);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="test"></param>
    /// <param name="result"></param>
    public override void RunTest(ITest test, TestResult result) {
      ThreadLittleHelper tlh = new ThreadLittleHelper(test, result, this);
      Thread t = new Thread(new ThreadStart(tlh.Run));
      t.Start();
    }
    void WaitUntilFinished() {
      lock(this) {
        while (fActiveTestDeathCount < TestCount) {
          try {
            Monitor.Wait(this);
          } catch (ThreadInterruptedException) {
            return; // TBD
          }
        } 
      }
    }
  /// <summary>
  /// 
  /// </summary>
  /// <param name="test"></param>
    public void RunFinished(ITest test) {
      lock(this) {
        fActiveTestDeathCount++;
        Monitor.PulseAll(this);
      }
    }
  }
}