Fix unit test failures#343
Conversation
…teChallengeMessage method
…n a hardcoded path.
|
Thanks,
|
|
Regarding the port randomization issue, the test fails almost every time for me (using the test runner built in to JetBrains Rider). One of the tests succeeds and the other gets a "port in use" error. I believe this is because it uses the time as the random seed, and the test runner runs tests in parallel, so they run at the exact same time. Note my fix still gives a 1/60000ish chance of failure. Alternatively I could write a static method that randomizes the port once, then increments it for each subsequent call. Or catches the error when it happens and increments the port number. Whatever you like. |
That's what I would have done, with Interlocked.Increment |
…rt number each time.
|
Updated to use Interlocked.Increment. |
| public class NTDirectoryFileSystemTests : NTFileStoreTests | ||
| { | ||
| private static readonly string TestDirectoryPath = @"C:\Tests"; | ||
| private static readonly string TestDirectoryPath = Path.Combine(Path.GetTempPath(), "SMBLibraryTests"); |
There was a problem hiding this comment.
Please avoid mixing two unrelated changes in the same pull request
| { | ||
| var next = Interlocked.Increment(ref m_serverPort); | ||
|
|
||
| if (next > maxPort) |
There was a problem hiding this comment.
It would be simpler to avoid a possible random value near port 65535 then to have this check
| { | ||
| m_serverPort = 1000 + new Random().Next(50000); | ||
| m_tcpListener = new TcpListener(IPAddress.Loopback, m_serverPort); | ||
| m_tcpListener = new TcpListener(IPAddress.Loopback, GetNextPortNumber()); |
There was a problem hiding this comment.
Just use
int port = Interlocked.Increment(ref s_serverPort);
No need for a method
| // by incrementing the port number for each test | ||
| private static readonly int minPort = 1025; | ||
| private static readonly int maxPort = 65535; | ||
| private static int m_serverPort = minPort + new Random().Next(maxPort - minPort); |
There was a problem hiding this comment.
Please rename to s_serverPort (I prefer s_ prefix for static variables)
57cfb6a to
336c47f
Compare
Running the unit tests in my environment resulted in some errors, which are fixed by these updates.