Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete erroneous Socket test #105448

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -688,35 +688,6 @@ public unsafe void Ctor_SafeHandle_SocketPair_Success()
close(ptr[1]);
}

// On some Unix machines the second (manual) handle close succeeds despite Socket's/SafeSocketHandle's Dispose
// completing a succesful close of the same handle value previously.
// We may investigate this, but it doesn't indicate incorrect behavior in Socket code,
// so making the test PlatformSpecific seems to be good enough. The SafeSocketHandle lifecycle logic is platform cross-platform.
[PlatformSpecific(TestPlatforms.Windows)]
[Theory]
[InlineData(false)]
[InlineData(true)]
public void Ctor_Dispose_HandleClosedIfOwnsHandle(bool ownsHandle)
{
Socket original = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IntPtr handleValue = original.Handle;

SafeSocketHandle handleClone = new SafeSocketHandle(handleValue, ownsHandle: ownsHandle);
Socket socketClone = new Socket(handleClone);
socketClone.Dispose();

bool manualCloseSucceeded = closesocket(handleValue) == 0;
Assert.Equal(!ownsHandle, manualCloseSucceeded);

#if DEBUG // The finalizer will fail to close the handle which leads to an assertion failure in Debug builds.
GC.SuppressFinalize(original);
GC.SuppressFinalize(original.SafeHandle);
#endif

[DllImport("ws2_32.dll", SetLastError = true)]
static extern int closesocket(IntPtr socketHandle);
}

private static void AssertEqualOrSameException<T>(Func<T> expected, Func<T> actual)
{
T r1 = default, r2 = default;
Expand Down
Loading