Hello!
I was getting sporadic (more often then not) port conflicts on this
unit test (/Test/Search/TestRemoteSearchable.cs). I rewrote the test a
bit, and I have not had problems since. If this looks good, how do I
submit the patch?
tjk :)
Index: TestRemoteSearchable.cs
===================================================================
--- TestRemoteSearchable.cs (revision 732813)
+++ TestRemoteSearchable.cs (working copy)
@@ -16,7 +16,7 @@
*/
using System;
-
+using System.Net.Sockets;
using NUnit.Framework;
using Lucene.Net.Documents;
@@ -38,13 +38,29 @@
private static int port;
private static bool serverStarted;
+ private const int MAX_PORT_TRIES = 10;
+
[SetUp]
public override void SetUp()
{
base.SetUp();
Random rnd = new Random((int)(DateTime.Now.Ticks &
0x7fffffff));
- port = rnd.Next(System.Net.IPEndPoint.MinPort,
System.Net.IPEndPoint.MaxPort);
- httpChannel = new
System.Runtime.Remoting.Channels.Http.HttpChannel(port);
+
+ int portTry = 0;
+ while (true)
+ {
+ try
+ {
+ port =
rnd.Next(System.Net.IPEndPoint.MinPort,
System.Net.IPEndPoint.MaxPort);
+ httpChannel = new
System.Runtime.Remoting.Channels.Http.HttpChannel(port);
+ break;
+ }
+ catch (SocketException)
+ {
+ if (++portTry > MAX_PORT_TRIES)
+ throw;
+ }
+ }
if (!serverStarted)
StartServer();
}