diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-12-05 20:08:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-05 20:08:26 +0300 |
commit | 269d509e42c3a359746f017d46c57c44a3cf3b39 (patch) | |
tree | 3755932cd169d2185167abbee10ee28a41b56ba0 /mcs | |
parent | e67673fac85d13882256893d1b61c08ca0fc13c6 (diff) |
Remove DNS lookups of the local hostname in tests (#18059)
This allows us to workaround issues we currently have in the macOS bot network where DNS lookup of the hostname fails.
Diffstat (limited to 'mcs')
6 files changed, 90 insertions, 45 deletions
diff --git a/mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessagingProvider.cs b/mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessagingProvider.cs index 41644a3505a..020520969aa 100644 --- a/mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessagingProvider.cs +++ b/mcs/class/Mono.Messaging.RabbitMQ/Mono.Messaging.RabbitMQ/RabbitMQMessagingProvider.cs @@ -43,33 +43,16 @@ namespace Mono.Messaging.RabbitMQ { public class RabbitMQMessagingProvider : IMessagingProvider { private int txCounter = 0; - private readonly uint localIp; + private readonly Guid localId; private readonly MessagingContextPool contextPool; public RabbitMQMessagingProvider () { - localIp = GetLocalIP (); + localId = Guid.NewGuid (); contextPool = new MessagingContextPool (new MessageFactory (this), CreateConnection); } - private static uint GetLocalIP () - { - String strHostName = Dns.GetHostName (); - IPHostEntry ipEntry = Dns.GetHostByName (strHostName); - foreach (IPAddress ip in ipEntry.AddressList) { - if (AddressFamily.InterNetwork == ip.AddressFamily) { - byte[] addr = ip.GetAddressBytes (); - uint localIP = 0; - for (int i = 0; i < 4 && i < addr.Length; i++) { - localIP += (uint) (addr[i] << 8 * (3 - i)); - } - return localIP; - } - } - return 0; - } - public IMessage CreateMessage () { return new MessageBase (); @@ -78,7 +61,7 @@ namespace Mono.Messaging.RabbitMQ { public IMessageQueueTransaction CreateMessageQueueTransaction () { Interlocked.Increment (ref txCounter); - string txId = localIp.ToString () + txCounter.ToString (); + string txId = localId.ToString () + "_" + txCounter.ToString (); return new RabbitMQMessageQueueTransaction (txId, contextPool); } diff --git a/mcs/class/System.Runtime.Remoting/Test/ActivationTests.cs b/mcs/class/System.Runtime.Remoting/Test/ActivationTests.cs index 5ea68f21d5a..f05d556b74f 100644 --- a/mcs/class/System.Runtime.Remoting/Test/ActivationTests.cs +++ b/mcs/class/System.Runtime.Remoting/Test/ActivationTests.cs @@ -30,7 +30,10 @@ namespace MonoTests.Remoting { try { - tcp = new TcpChannel (0); + Hashtable tcpOptions = new Hashtable (); + tcpOptions ["port"] = 0; + tcpOptions ["bindTo"] = "127.0.0.1"; + tcp = new TcpChannel (tcpOptions, null, null); Hashtable options = new Hashtable (); options ["timeout"] = 10000; // 10s @@ -42,8 +45,8 @@ namespace MonoTests.Remoting AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation"); server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer"); - var tcpUrlPrefix = $"tcp://localhost:{server.TcpPort}"; - var httpUrlPrefix = $"http://localhost:{server.HttpPort}"; + var tcpUrlPrefix = $"tcp://127.0.0.1:{server.TcpPort}"; + var httpUrlPrefix = $"http://127.0.0.1:{server.HttpPort}"; RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), tcpUrlPrefix); RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), httpUrlPrefix); RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), tcpUrlPrefix + "/wkoSingleCall1"); @@ -169,8 +172,14 @@ namespace MonoTests.Remoting { TcpPort = NetworkHelpers.FindFreePort (); HttpPort = NetworkHelpers.FindFreePort (); - tcp = new TcpChannel (TcpPort); - http = new HttpChannel (HttpPort); + IDictionary tcpProps = new Hashtable (); + IDictionary httpProps = new Hashtable (); + tcpProps ["port"] = TcpPort; + tcpProps ["bindTo"] = "127.0.0.1"; + httpProps ["port"] = HttpPort; + httpProps ["bindTo"] = "127.0.0.1"; + tcp = new TcpChannel (tcpProps, null, null); + http = new HttpChannel (httpProps, null, null); ChannelServices.RegisterChannel (tcp); ChannelServices.RegisterChannel (http); diff --git a/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs b/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs index a8a9a7bfead..79edd736627 100644 --- a/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs +++ b/mcs/class/System.Runtime.Remoting/Test/GenericTest.cs @@ -172,6 +172,7 @@ namespace MonoTests.Remoting IDictionary props = new Hashtable (); props ["name"] = Guid.NewGuid ().ToString("N"); props ["port"] = port; + props ["bindTo"] = "127.0.0.1"; TcpChannel chan = new TcpChannel (props, null, null); ChannelServices.RegisterChannel (chan); diff --git a/mcs/class/System.Runtime.Remoting/Test/HttpBugTests.cs b/mcs/class/System.Runtime.Remoting/Test/HttpBugTests.cs index 553c58a580b..b80d79fd12f 100644 --- a/mcs/class/System.Runtime.Remoting/Test/HttpBugTests.cs +++ b/mcs/class/System.Runtime.Remoting/Test/HttpBugTests.cs @@ -20,11 +20,15 @@ namespace MonoTests.Remoting.Http [Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")] public void Test () { - new HttpChannel (8086); + var port = NetworkHelpers.FindFreePort (); + Hashtable props = new Hashtable (); + props["port"] = port; + props["bindTo"] = "127.0.0.1"; + new HttpChannel (props, null, null); RemotingServices.Marshal (new Service (), "test"); Service remObj = (Service) RemotingServices.Connect ( - typeof (Service), "http://localhost:8086/test"); + typeof (Service), $"http://127.0.0.1:{port}/test"); ArrayList list; remObj.Test (out list); @@ -70,13 +74,16 @@ namespace MonoTests.Remoting.Http public void Main () { var port = NetworkHelpers.FindFreePort (); - channel = new HttpChannel (port); + Hashtable props = new Hashtable (); + props["port"] = port; + props["bindTo"] = "127.0.0.1"; + channel = new HttpChannel (props, null, null); ChannelServices.RegisterChannel (channel); RemotingConfiguration.RegisterWellKnownServiceType (typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton); Bug321420 s = (Bug321420) Activator.GetObject (typeof - (Bug321420), $"http://localhost:{port}/Server.soap"); + (Bug321420), $"http://127.0.0.1:{port}/Server.soap"); // this works: s.Method ("a", "b"); s.Method ("a", "a"); @@ -101,7 +108,7 @@ namespace MonoTests.Remoting.Http public void Main () { Foo foo = (Foo) Activator.GetObject (typeof (Foo), - $"http://localhost:{server.HttpPort}/Test"); + $"http://127.0.0.1:{server.HttpPort}/Test"); Bar bar = foo.Login (); if (bar != null) @@ -146,7 +153,10 @@ namespace MonoTests.Remoting.Http public void Start () { HttpPort = NetworkHelpers.FindFreePort (); - c = new HttpChannel (HttpPort); + Hashtable props = new Hashtable (); + props["port"] = HttpPort; + props["bindTo"] = "127.0.0.1"; + c = new HttpChannel (props, null, null); ChannelServices.RegisterChannel (c); Type t = typeof(Foo); @@ -174,11 +184,14 @@ namespace MonoTests.Remoting.Http [Test] public void Main () { - channel = new HttpChannel (0); + Hashtable props = new Hashtable (); + props["port"] = 0; + props["bindTo"] = "127.0.0.1"; + channel = new HttpChannel (props, null, null); ChannelServices.RegisterChannel (channel); MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect ( typeof (IFactorial), - $"http://localhost:{server.HttpPort}/MyEndPoint"); + $"http://127.0.0.1:{server.HttpPort}/MyEndPoint"); IFactorial cal = (IFactorial) obj; Assert.AreEqual (cal.CalculateFactorial (4), 24); } @@ -216,7 +229,10 @@ namespace MonoTests.Remoting.Http public void Start () { HttpPort = NetworkHelpers.FindFreePort (); - c = new HttpChannel (HttpPort); + Hashtable props = new Hashtable (); + props["port"] = HttpPort; + props["bindTo"] = "127.0.0.1"; + c = new HttpChannel (props, null, null); ChannelServices.RegisterChannel (c); Type t = typeof(Calculator); diff --git a/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs b/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs index b7bad06cf95..d5e1e44a500 100644 --- a/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs +++ b/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs @@ -294,6 +294,7 @@ namespace MonoTests.Remoting IDictionary props = new Hashtable ();
props ["name"] = objMarshal.Uri;
props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
@@ -317,6 +318,7 @@ namespace MonoTests.Remoting IDictionary props = new Hashtable ();
props ["name"] = objMarshal.Uri;
props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
@@ -346,7 +348,10 @@ namespace MonoTests.Remoting public void ExecuteMessage ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
MarshalObject objMarshal = NewMarshalObject ();
@@ -379,7 +384,10 @@ namespace MonoTests.Remoting public void IsOneWay ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);
@@ -403,7 +411,10 @@ namespace MonoTests.Remoting public void GetObjRefForProxy ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
// Register le factory as a SAO
@@ -427,7 +438,10 @@ namespace MonoTests.Remoting public void GetRealProxy ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);
@@ -449,7 +463,10 @@ namespace MonoTests.Remoting public void SetObjectUriForMarshal ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
MarshalObject objRem = NewMarshalObject ();
@@ -469,7 +486,10 @@ namespace MonoTests.Remoting public void GetServeurTypeForUri ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
Type type = typeof (MarshalObject);
ChannelServices.RegisterChannel (chn);
try {
@@ -491,7 +511,10 @@ namespace MonoTests.Remoting public void IsObjectOutOf ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject2.rem", WellKnownObjectMode.Singleton);
@@ -514,7 +537,10 @@ namespace MonoTests.Remoting {
var port = NetworkHelpers.FindFreePort ();
RemotingConfiguration.ApplicationName = "app";
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "obj3.rem", WellKnownObjectMode.Singleton);
@@ -541,7 +567,10 @@ namespace MonoTests.Remoting public void GetObjectWithChannelDataTest ()
{
var port = NetworkHelpers.FindFreePort ();
- TcpChannel chn = new TcpChannel (port);
+ IDictionary props = new Hashtable ();
+ props ["port"] = port;
+ props ["bindTo"] = "127.0.0.1";
+ TcpChannel chn = new TcpChannel (props, null, null);
ChannelServices.RegisterChannel (chn);
try {
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "getobjectwithchanneldata.rem", WellKnownObjectMode.Singleton);
diff --git a/mcs/class/System.Runtime.Remoting/Test/TcpCalls.cs b/mcs/class/System.Runtime.Remoting/Test/TcpCalls.cs index 1e28d511f89..293ca6338f9 100644 --- a/mcs/class/System.Runtime.Remoting/Test/TcpCalls.cs +++ b/mcs/class/System.Runtime.Remoting/Test/TcpCalls.cs @@ -7,6 +7,7 @@ // using System; +using System.Collections; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; @@ -55,12 +56,18 @@ namespace MonoTests.Remoting { public override IChannelSender CreateClientChannel () { - return new TcpChannel (0); + Hashtable props = new Hashtable (); + props["port"] = 0; + props["bindTo"] = "127.0.0.1"; + return new TcpChannel (props, null, null); } public override IChannelReceiver CreateServerChannel () { - return new TcpChannel (0); + Hashtable props = new Hashtable (); + props["port"] = 0; + props["bindTo"] = "127.0.0.1"; + return new TcpChannel (props, null, null); } } } |