title: NUnit and testing in different threads
body: <p>I'm testing an application. A <code>[TearDown]</code> methods contains another method which sends a request a server. This one is pretty slow. Meanwhile a server is unable to handle more than 3 requests at the same time. </p>
  
  <p>So I decided to use a semaphore.</p>
  
  <pre><code>   [TestFixture]
      public class TestBase
      {
          private const int MaxThreadsCount = 3;
          private readonly Semaphore _semaphore = new Semaphore(MaxThreadsCount, MaxThreadsCount);
  
          [SetUp]
          public virtual void Setup()
          {
          }
  
          [TearDown]
          public void CleanUp()
          {
              //...some code
              new Thread(_ =&gt; SendRequestAsync("url/of/a/server", parameters)).Start();
          }
  
          private void SendRequestAsync(string url, NameValueCollection parameters)
          {
              _semaphore.WaitOne();
              string result = MyServerHelper.SendRequest(url, parameters); 
              Assert.That(string.IsNullOrEmpty(result), Is.False, "SendRequest returned false");
          }
  
          [Test]
          public void Test01()
          {
              Assert.AreEqual(1, 1);
          }
  
          [Test]
          public void Test02()
          {
              Assert.AreEqual(1, 1);
          }
  
          [Test]
          public void Test03()
          {
              Assert.AreEqual(1, 1);
          }
          //...........................
          [Test]
          public void TestN()
          {
              Assert.AreEqual(1, 1);
          }
      } 
  </code></pre>
  
  <p>However it seems like it does not work properly. Now in log file on a server there are no records, which means a server does not receive any requests.</p>
  
  <p>1) What did I do wrong?</p>
  
  <p>2) How do I initialize a semaphore:</p>
  
  <pre><code>private readonly Semaphore _semaphore = new Semaphore(MaxThreadsCount, MaxThreadsCount);
  </code></pre>
  
  <p>or </p>
  
  <pre><code>private readonly Semaphore _semaphore = new Semaphore(0, MaxThreadsCount);
  </code></pre>