This is the addition of a quick and dirty NUnit test for Bug 4786
authorRobert Wilkens <robwilkens@robwilkens-HP-Pavilion-g6-Notebook-PC.(none)>
Thu, 3 May 2012 12:05:55 +0000 (08:05 -0400)
committerRobert Wilkens <robwilkens@robwilkens-HP-Pavilion-g6-Notebook-PC.(none)>
Thu, 3 May 2012 12:05:55 +0000 (08:05 -0400)
This bug was fixed in another commit/push by Robert Wilkens (me).
This NUnit test will fail without the patch (It will raise a
NullReferenceException from within mono), but with the patch for that
bug it will not raise an exception and the test will exit cleanly.

Please note, the top of this patch source sets up a temporary network
socket to listen to a port which pool.GetConnection() simply tries to connect
to.  No data is transfered so nothing needed to be done other than to
call Listen() on that socket which was bound to the port.  If the listen fails,
it means something else is listening already, which is fine, so we ignore
any excpetions from this part of the code (catch and ignore).

mcs/class/Mono.Data.Tds/Makefile
mcs/class/Mono.Data.Tds/Mono.Data.Tds_test.dll.sources [new file with mode: 0644]
mcs/class/Mono.Data.Tds/Test/bug-4786.cs [new file with mode: 0644]

index 80c552ae754acd8aec3130c2dc875ad821775082..53ed46d7b7fdb1caebe521ce021829ee08ba9445 100644 (file)
@@ -4,6 +4,7 @@ include ../../build/rules.make
 
 LIBRARY = Mono.Data.Tds.dll
 LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:System.Xml.dll /r:Mono.Security.dll
-NO_TEST = yes
+
+TEST_MCS_FLAGS = /r:System.dll /r:System.Net.dll 
 
 include ../../build/library.make
diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds_test.dll.sources b/mcs/class/Mono.Data.Tds/Mono.Data.Tds_test.dll.sources
new file mode 100644 (file)
index 0000000..5cefc19
--- /dev/null
@@ -0,0 +1 @@
+bug-4786.cs
diff --git a/mcs/class/Mono.Data.Tds/Test/bug-4786.cs b/mcs/class/Mono.Data.Tds/Test/bug-4786.cs
new file mode 100644 (file)
index 0000000..8bea4a3
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// bug-4786.cs- 
+//      NUnit Test Cases for Mono.Data.Tds.Protocol.TdsConnectionPool
+//
+// Author:
+//      Robert Wilkens <robwilkens@gmail.com>
+//
+// Copyright (C) 2012 Robert Wilkens (http://www.robssoftwareprojects.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace bug4786test
+{
+       
+  using NUnit.Framework;
+  using Mono.Data.Tds.Protocol;
+  using System;
+  using System.Net;
+  using System.Net.Sockets;
+
+
+  [TestFixture]
+  public class TdsConnectionPoolTest
+  {
+    //const string SERVER="robwilkenssql.db.6210828.hostedresource.com";
+    const string SERVER="localhost";
+    [Test]
+    public void CheckNullException() 
+    {
+
+       //set up dummy sql listener, if there is a real sql server on this
+       //machine at that port, in theory this part will fail, but that's ok
+       //becuase something will be listening on the port and that's all we
+       //require at this point: a listener on port 1433...
+
+       try{
+               Socket Listener = new Socket(AddressFamily.InterNetwork, 
+                                         SocketType.Stream,
+                                         ProtocolType.Tcp);
+               IPAddress hostIP =Dns.GetHostEntry("localhost").AddressList[0];
+               IPEndPoint ep = new IPEndPoint(hostIP, 1433);
+               Listener.Bind(ep); 
+               Listener.Listen(1);
+       } catch (Exception){
+               //ignore
+       }
+
+       //try to connect twice, in earlier failure would get null exception
+       //on 2nd call to pool.GetConnection();
+       //Most of this code ripped from sqlConnection.Open()
+
+       TdsConnectionPool pool;
+       
+       TdsConnectionPoolManager sqlConnectionPools = 
+               new TdsConnectionPoolManager(TdsVersion.tds80); 
+       TdsConnectionInfo info=
+               new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/,
+               8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/,
+               100/*maxpoolsize*/);
+       pool=sqlConnectionPools.GetConnectionPool("test",info);
+       Tds tds=null;
+
+       //this first one succeeded regardless as long as something answered
+       //the phone on port 1433 of localhost
+       tds=pool.GetConnection();
+
+       pool.ReleaseConnection(tds);
+
+
+       // 2nd time thru: This will fail with nullreferenceexception 
+       // at pool.GetConnection() unless the patch by Rob Wilkens which 
+       // adds "result=null;" before retry in pool.getConnection() source
+
+       //First let's pretend we're calling this test fresh, as if we
+       //call sqlConnection.Open() again :
+
+       info=new TdsConnectionInfo(SERVER/*dummyhost*/,1433/*port*/,
+               8192/*pktsize*/,15/*timeout*/,0/*minpoolsize*/,
+               100/*maxpoolsize*/);
+
+       pool=sqlConnectionPools.GetConnectionPool("test",info);
+
+       //Then: Test for failure (will raise uncaught exception which
+       //causes failure of test if bug is not fixed
+       tds=pool.GetConnection();
+
+       pool.ReleaseConnection(tds);
+
+       //exit
+    }
+  }
+}
+