From e9d723427d3bba7c2845d05e6d0f6435002fb4e3 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 30 Mar 2020 11:07:16 -0400 Subject: [PATCH 1/2] [Harness] If we cannot connect over tcp use Console.Out as the writer. If we could not connect to the host via tcp, set the writer to be Console.Out which will fix the NRE and will report the test run in the runlogs. fixes: https://github.com/xamarin/xamarin-macios/issues/8130 --- .../Managed/Resources/src/iOSApp/ViewController.cs | 2 +- .../Managed/Resources/src/tvOSApp/ViewController.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs index c1ce0e30ed67..e483d5ac9aec 100644 --- a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs +++ b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs @@ -67,7 +67,7 @@ public async override void ViewDidLoad () writer = new TcpTextWriter (options.HostName, options.HostPort); } catch (Exception ex) { Console.WriteLine ("Network error: Cannot connect to {0}:{1}: {2}. Continuing on console.", options.HostName, options.HostPort, ex); - writer = null; // will default to the console + writer = Console.Out; // will default to the console } } diff --git a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs index 6fd0a0a288d1..eef790f9dbbc 100644 --- a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs +++ b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs @@ -64,8 +64,14 @@ public async override void ViewDidLoad () base.ViewDidLoad (); var options = ApplicationOptions.Current; TcpTextWriter writer = null; - if (!string.IsNullOrEmpty (options.HostName)) - writer = new TcpTextWriter (options.HostName, options.HostPort); + if (!string.IsNullOrEmpty (options.HostName)) { + try { + writer = new TcpTextWriter (options.HostName, options.HostPort); + } catch (Exception ex) { + Console.WriteLine ("Network error: Cannot connect to {0}:{1}: {2}. Continuing on console.", options.HostName, options.HostPort, ex); + writer = Console.Out; // will default to the console + } + } // we generate the logs in two different ways depending if the generate xml flag was // provided. If it was, we will write the xml file to the tcp writer if present, else From 1aa16455056ab8d426a6c938d257b3e3a96d6bad Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 30 Mar 2020 15:45:28 -0400 Subject: [PATCH 2/2] Manuel is an imbecil and did not run test locally. --- .../Templates/Managed/Resources/src/iOSApp/ViewController.cs | 4 ++-- .../Templates/Managed/Resources/src/tvOSApp/ViewController.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs index e483d5ac9aec..7e462928b24f 100644 --- a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs +++ b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/iOSApp/ViewController.cs @@ -67,7 +67,7 @@ public async override void ViewDidLoad () writer = new TcpTextWriter (options.HostName, options.HostPort); } catch (Exception ex) { Console.WriteLine ("Network error: Cannot connect to {0}:{1}: {2}. Continuing on console.", options.HostName, options.HostPort, ex); - writer = Console.Out; // will default to the console + writer = null; // will default to the console } } @@ -102,7 +102,7 @@ public async override void ViewDidLoad () break; } if (options.EnableXml) { - runner.WriteResultsToFile (writer, jargon); + runner.WriteResultsToFile (writer ?? Console.Out, jargon); logger.Info ("Xml file was written to the tcp listener."); } else { string resultsFilePath = runner.WriteResultsToFile (jargon); diff --git a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs index eef790f9dbbc..91be0889a23e 100644 --- a/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs +++ b/tests/xharness/BCLTestImporter/Templates/Managed/Resources/src/tvOSApp/ViewController.cs @@ -69,7 +69,7 @@ public async override void ViewDidLoad () writer = new TcpTextWriter (options.HostName, options.HostPort); } catch (Exception ex) { Console.WriteLine ("Network error: Cannot connect to {0}:{1}: {2}. Continuing on console.", options.HostName, options.HostPort, ex); - writer = Console.Out; // will default to the console + writer = null; // will default to the console } } @@ -103,7 +103,7 @@ public async override void ViewDidLoad () break; } if (options.EnableXml) { - runner.WriteResultsToFile (writer, jargon); + runner.WriteResultsToFile (writer ?? Console.Out, jargon); logger.Info ("Xml file was written to the tcp listener."); } else { string resultsFilePath = runner.WriteResultsToFile (jargon);