dotnet / dotnet/macios

Show better error for device not having network connection when running unit tests

Open
#6,809 1 comment 0 reactions 0 assignees View on GitHub
enhancement iOS tests
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

# Steps to Reproduce

1. Put iOS device into flight mode and turn off WiFi
2. `make -C tests runner`
3. Run `mscorlib - iOS Unified 64-bits - device - Debug` device tests

### Expected Behavior

A nice error message that tells me to enable network connection.

### Actual Behavior

The unit test app starts on the device but immediately crashes with a confusing exception:

```
21:16:21.3879290 2019-08-20 21:16:21.384 com.xamarin.bcltests.mscorlib[583:145485]
21:16:21.3879490 Unhandled Exception:
21:16:21.3879520 System.ArgumentNullException: Value cannot be null.
21:16:21.3879540 Parameter name: hostname
21:16:21.3879570 at System.Net.Sockets.TcpClient..ctor (System.String hostname, System.Int32 port) [0x00075] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Sockets/TCPClient.cs:126
21:16:21.3879600 at BCLTests.TestRunner.Core.TcpTextWriter..ctor (System.String hostName, System.Int32 port) [0x000b1] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/common/TestRunner.Core/TcpTextWriter.cs:87
21:16:21.3879630 at BCLTests.ViewController.ViewDidLoad () [0x00060] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/iOSApp/ViewController.cs:70
21:16:21.3880260 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
21:16:21.3880320 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/Foundation/NSAction.cs:178
21:16:21.3880360 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
21:16:21.3880380 at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/UIKit/UIApplication.cs:86
21:16:21.3880410 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/UIKit/UIApplication.cs:65
21:16:21.3880440 at BCLTests.Application.Main (System.String[] args) [0x00001] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/iOSApp/Main.cs:10
21:16:21.3880470 2019-08-20 21:16:21.386 com.xamarin.bcltests.mscorlib[583:145485] Unhandled managed exception: Value cannot be null.
21:16:21.3880720 Parameter name: hostname (System.ArgumentNullException)
21:16:21.3880770 at System.Net.Sockets.TcpClient..ctor (System.String hostname, System.Int32 port) [0x00075] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Sockets/TCPClient.cs:126
21:16:21.3880810 at BCLTests.TestRunner.Core.TcpTextWriter..ctor (System.String hostName, System.Int32 port) [0x000b1] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/common/TestRunner.Core/TcpTextWriter.cs:87
21:16:21.3880840 at BCLTests.ViewController.ViewDidLoad () [0x00060] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/iOSApp/ViewController.cs:70
21:16:21.3880860 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
21:16:21.3881120 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/Foundation/NSAction.cs:178
21:16:21.3881180 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
21:16:21.3881210 at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/UIKit/UIApplication.cs:86
21:16:21.3881250 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/alexander/dev/xamarin-macios/xamarin-macios/src/UIKit/UIApplication.cs:65
21:16:21.3881270 at BCLTests.Application.Main (System.String[] args) [0x00001] in /Users/alexander/dev/xamarin-macios/xamarin-macios/tests/bcl-test/templates/iOSApp/Main.cs:10

```

### Environment

xamarin-macios master@acb7b76ce59d11a045630c74c85432cd7418fce1

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.