27 Commits
Author SHA1 Message Date
Rolf Bjarne Kvinge c93db5b047 [System] Refactor tests to use system-assigned ports whenever possible. (#11829)
Refactor tests to use system-assigned ports whenever possible, so that we
avoid the potential race condition in NetworkHelpers.FindFreePort.

This should make it much less probable to run into spurious "Address already
in use" exceptions.

In some cases I kept the call to NetworkHelpers.FindFreePort:

* When the test is not binding/listening on a port, but instead trying to
  connect to an inexistent port (for tests that verifies error handling /
  exceptions). In this case there is still a race condition (if a test tries
  to verify that a connection fails, it may unexpectedly succeed instead).

* Sometimes the test doesn't actually use the port (the test is verifying
  something very different, for instance a ArgumentNullExceptions, which are
  thrown before the port is used).

* Some API doesn't allow for requesting a system assigned port:

    * HttpListener: in this case I elected to re-try a few times in case of
      "Address already in use" exceptions.

    * The 'UdpClient (string, port)' constructor (other constructors work
      fine): these turned out a bit complicated to work around (or would
      modify the test more than would be reasonable), so for these we still
      have to hope for the best.

Hopefully fixes https://github.com/xamarin/maccore/issues/604.
2018-11-29 14:02:07 +01:00
Alexander Köplinger e7a2d94f75 [bcl] Fix a few hardcoded socket ports in tests (#5471)
* [System] Fix a few hardcoded socket ports in tests

Those could've shown up as "address already in use" in CI.

* [System.Runtime.Remoting] Fix a few hardcoded socket ports in tests

Those could've shown up as "address already in use" in CI.

Additionally remove a copy of RemotingServicesTest.cs from corlib
which also exists in System.Runtime.Remoting in updated form.

* [System.ServiceModel] Fix a few hardcoded socket ports in tests

Those could've shown up as "address already in use" in CI.

* [System.Net.Http] Fix a few hardcoded socket ports in tests

Those could've shown up as "address already in use" in CI.

The additional "keep-alive" header in Send_Complete_NoContent() and
Send_Transfer_Encoding_Chunked() is because we were using the same
port for all tests before so other tests would clear the header.
This doesn't happen now that we use distinct test ports.

* [System.ServiceModel.Web] Fix a few hardcoded socket ports in tests

Those could've shown up as "address already in use" in CI.
2017-08-31 10:53:35 +02:00
Marek Safar cf3f3aa8d1 [System] Add new test 2016-12-08 17:16:38 -08:00
Marek Safar c143e55c45 [System] More Socket methods from referencesource 2016-10-17 15:04:39 +02:00
Marek Safar c79b08d83c [System] More Socket types from referencesource 2016-10-12 10:14:03 +02:00
Rolf Bjarne Kvinge e6536dd5e1 [System*] Throw a PlatformNotSupported exception when using the networking stack on watchOS. (#3606)
* [System] Fix line endings for a few files.

Best reviewed by not showing whitespace changes (should be empty diff in that case).

* [System] Fix potential crash in CookieParserTests.

Socket.EndAccept can throw an exception, which will crash the process if it
happens on a threadpool. So handle any exceptions when calling
Socket.EndAccept, and propagate those exceptions out of any threadpool code.

* [System.Net.Http] Throw a PlatformNotSupported exception when using HttpClientHandler on watchOS.

* [System.Net.Http] Tweak tests after watchOS API change.

Unfortunately the [ExpectedException] attribute can't be put on an entire
class, so remove the [Category ("RequiresBSDSockets")] attribute on the class
and instead decorate each test with an [ExpectedException] attribute.

* [System] Extract the HttpListenerResponseHelper class to a separate file.

Extract the HttpListenerResponseHelper class to a separate file so that it's
easier to replace the HttpListenerResponse implementation by using a different
file.

* [System] Throw a PlatformNotSupported exception when using the networking stack on watchOS.

* [System] Tweak tests after watchOS API changes.

Unfortunately the [ExpectedException] attribute can't be put on an entire
class, so remove the [Category ("RequiresBSDSockets")] attribute on the class
and instead decorate each test with an [ExpectedException] attribute.

* [System] Fix potential crash in SocketAcceptAsyncTest.

Fix potential crash in SocketAcceptAsyncTest by catching any exceptions in
code executed on the threadpool so that we never end up with unhandled
exceptions (which may terminate the process).

* [System] Avoid logic in SetUp attributes in tests.

Any type of exception in [SetUp] attributes causes all tests to fail with that
exception.

This even happens for tests that do not need the logic in the [SetUp]
attribute.

So rewrite tests a bit to not use [SetUp] when we can reasonably avoid it, and
instead instantiate class-level variables on first use. This ensures that any
exceptions that occur when initializing those variables are attributed to the
corresponding test, and not all of them.

* [System] Make exception handler (for test) catch more exceptions to avoid unhandled exceptions causing process termination.

* [System] Remove Obsolete attribute on API that throws PNSE.
2016-09-27 13:13:38 +02:00
Rolf Bjarne Kvinge 51de6e83eb [System*] Add category for tests that use API that require BSD sockets.
We don't have access to BSD sockets on watchOS, so that API
doesn't work.

With this category we'll be able to exclude these tests.
2016-07-26 13:20:51 +02:00
Alexander Köplinger 1492386668 [System/ServiceModel] Fix more hardcoded test ports
A test failed on Jenkins today with "address already in use".
Opportunistically replaced a few more hardcoded test ports to avoid failures in the future.
2016-03-05 15:50:28 +01:00
Ludovic Henry 83c7edc70e [SocketResponder] Start in constructor and Stop on Dispose
In conjuction with `using` we ensure that we Start and Stop the SocketResponder correctly, and everytime
2016-01-28 11:10:53 +00:00
Ludovic Henry 7f0b7cf022 [Tests] Use explicit delegate so it appears in stacktraces
In case of exception in this callback, the name of the test method will appear in the stacktrace, making debugging way easier.
2016-01-28 11:10:53 +00:00
Alex Rønne Petersen ceff52c9ae [bcl] Deduplicate the SocketResponder test helper class.
A number of fixes were made to the version in System but these fixes were never
applied to the System.Web.Services version. Merge the two and place the class
in the test-helpers directory to avoid this sort of maintenance problem.
2016-01-14 03:32:23 +01:00
Alexander Köplinger 746650d1b9 [bcl] Remove more NET_2_0 checks from class libs 2015-01-17 05:45:39 +01:00
Robert Jordan 2f26089775 2009-06-26 Robert Jordan <[email protected]>
* *.cs: Upgrade to new NUnit style.


svn path=/trunk/mcs/; revision=136949
2009-06-26 12:20:08 +00:00
Arina Itkes ddaf734d6a Fix for 9491 bug. Socket should not throw exception when it closed by another thread.
svn path=/trunk/mcs/; revision=91709
2007-12-20 14:30:11 +00:00
Arina Itkes 0d0309405c TARGET_JVM: Move Category NotWorking to CloseTest instead of TcpClient
svn path=/trunk/mcs/; revision=90143
2007-11-22 10:47:30 +00:00
Arina Itkes c5c44ce2af TARGET_JVM: mark some tests with NotWorking under TARGET_JVM
svn path=/trunk/mcs/; revision=90140
2007-11-22 10:33:32 +00:00
Gert Driesen 13b7e81515 * SocketResponder.cs: Thread-safety fixes.
* TcpClientTest.cs: Enabled test for bug #81105.

svn path=/trunk/mcs/; revision=76068
2007-04-22 16:19:52 +00:00
Gert Driesen 9b688e5d1e * TcpClientTest.cs: ... and disable it again, since it fails buildbot
sles-9 x86-64.

svn path=/trunk/mcs/; revision=76022
2007-04-20 19:46:01 +00:00
Gert Driesen 9dc8fb6d4d * TcpClientTest.cs: Re-enabled test for bug #81105 since it passes
on both linux and windows. I'll monitor the build bots to spot if it
breaks the tests.

svn path=/trunk/mcs/; revision=76020
2007-04-20 18:43:10 +00:00
Miguel de Icaza 4addb2731e Flag as not working for now
svn path=/trunk/mcs/; revision=74338
2007-03-15 05:10:26 +00:00
Gert Driesen 155199945b * TcpClient.cs: Do not initialize network stream in Connect. In
Dispose, only nullify client if network stream was not obtained.
Fixes bug #81105.
* TcpClientTest.cs: Added test for bug #81105.

svn path=/trunk/mcs/; revision=74062
2007-03-11 13:02:52 +00:00
Dick Porter f75e3a4aac 2007-01-23 Dick Porter <[email protected]>
* TcpClient.cs: 2.0 profile updates, based on a patch by Sridhar
	Kulkarni ([email protected])

2007-01-23  Dick Porter  <[email protected]>

	* TcpClientTest.cs: Test 2.0 Connect(IPAddress[], port) overload



svn path=/trunk/mcs/; revision=71557
2007-01-23 21:08:28 +00:00
Ben Maurer 0e8decdb37 remove svn:executable from .cs files
svn path=/trunk/mcs/; revision=46562
2005-06-27 15:51:40 +00:00
Nick Drochak f44d1cb31a 2005-03-06 Nick Drochak <[email protected]>
* TcpClientTest.cs: Choose a different port so test will pass on MS.NET
	* TcpListenerTest.cs: Ignore test that doesn't play well on MS.NET

svn path=/trunk/mcs/; revision=41482
2005-03-06 13:47:13 +00:00
Martin Willemoes Hansen 2320c1fddc * Removed: Old AllTests.cs files
* NUnit20ified the tests.

svn path=/trunk/mcs/; revision=12666
2003-03-18 21:45:41 +00:00
Martin Baulig b5189359b3 2002-02-27 Martin Baulig <[email protected]>
* System_test.build: Build new executable RunTests.System.exe which you can
	use to run the tests on Linux.

	* NameValueCollectionTest.cs: Split out BasicOperationTest into
	BasicOperationTest.cs.

	* AllTests.cs: Use namespace Ximian.Mono.Tests.System instead of
	Ximian.Mono.Tests.

	* DnsTest.cs: Put this into namespace Ximian.Mono.Tests.Systeam.
	* NameValueCollectionTest.cs: Likewise.
	* StringCollectionTest.cs: Likewise.

svn path=/trunk/mcs/; revision=2732
2002-02-27 15:00:14 +00:00
Miguel de Icaza 2254f098fb Add TcpClient and TcpListener from Phillip Pearson
svn path=/trunk/mcs/; revision=1431
2001-11-23 21:07:52 +00:00