--- PoolingTests-snap.cs 2008-01-04 10:32:31.000000000 +1100 +++ PoolingTests.cs 2008-01-04 10:30:18.000000000 +1100 @@ -247,6 +247,96 @@ } } + /// + /// Worker thread for the Semaphore Pooling Test + /// + class SemaphoreTestWorker + { + MySqlConnection con; + SemaphoreTestDispatcher dispatch; + + public SemaphoreTestWorker(MySqlConnection c, SemaphoreTestDispatcher d) + { + con = c; + dispatch = d; + } + + public void Start() + { + Random rand = new Random(); + + for (int i = 0; i < 5; i++) + { + MySqlCommand cmd = new MySqlCommand("SELECT 1", con); + cmd.ExecuteNonQuery(); + } + + Thread.Sleep(3000); + con.Close(); + + dispatch.CompleteOne(); + } + } + + /// + /// Handler class for dispatching worker threads for + /// the Semaphore Pooling Test and managing their return values. + /// + class SemaphoreTestDispatcher + { + const int ThreadCount = 50; + int completeCount = 0; + object lockCount = new object(); + + public void Run(string connStr) + { + Thread[] threads = new Thread[ThreadCount]; + + for (int i = 0; i < ThreadCount; i++) + { + MySqlConnection c = new MySqlConnection(connStr); + c.Open(); + + SemaphoreTestWorker worker = new SemaphoreTestWorker(c, this); + threads[i] = new Thread(new ThreadStart(worker.Start)); + threads[i].Start(); + } + + // Wait for threads to return + foreach (Thread t in threads) + t.Join(); + } + + public void CompleteOne() + { + lock (lockCount) + completeCount++; + } + + public bool Success + { + get + { + lock (lockCount) + return completeCount == ThreadCount; + } + } + } + + /// + /// Bug #33682 Semaphore class is Windows only preventing mono from using connector + /// + [Test] + public void SemaphoreConcurrentThreads() + { + string connStr = GetConnectionString(true) + ";pooling = true; max pool size=25"; + + SemaphoreTestDispatcher dispatcher = new SemaphoreTestDispatcher(); + dispatcher.Run(connStr); + + Assert.IsTrue(dispatcher.Success); + } + /// /// Bug #29409 Bug on Open Connection with pooling=true to a MYSQL Server that is shutdown ///