66using System . Linq ;
77using System . Net . Sockets ;
88using System . Threading . Tasks ;
9+ using Microsoft . DotNet . RemoteExecutor ;
910using Microsoft . DotNet . XUnitExtensions ;
1011using Xunit ;
1112
@@ -28,72 +29,92 @@ public static void EventSource_ExistsWithCorrectId()
2829 Assert . NotEmpty ( EventSource . GenerateManifest ( esType , "assemblyPathToIncludeInManifest" ) ) ;
2930 }
3031
31- [ ConditionalFact ]
32+ [ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
3233 public void GetHostEntry_InvalidHost_LogsError ( )
3334 {
34- using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Error ) )
35+ try
3536 {
36- var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
37-
38- listener . RunWithCallback ( ev => events . Enqueue ( ev ) , ( ) =>
37+ RemoteExecutor . Invoke ( static ( ) =>
3938 {
40- try
41- {
42- Dns . GetHostEntry ( Configuration . Sockets . InvalidHost ) ;
43- throw new SkipTestException ( "GetHostEntry should fail but it did not." ) ;
44- }
45- catch ( SocketException e ) when ( e . SocketErrorCode == SocketError . HostNotFound )
39+ using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Error ) )
4640 {
41+ var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
42+
43+ listener . RunWithCallback ( ev => events . Enqueue ( ev ) , ( ) =>
44+ {
45+ try
46+ {
47+ Dns . GetHostEntry ( Configuration . Sockets . InvalidHost ) ;
48+ throw new SkipTestException ( "GetHostEntry should fail but it did not." ) ;
49+ }
50+ catch ( SocketException e ) when ( e . SocketErrorCode == SocketError . HostNotFound )
51+ {
52+ }
53+ catch ( Exception e )
54+ {
55+ throw new SkipTestException ( $ "GetHostEntry failed unexpectedly: { e . Message } ") ;
56+ }
57+ } ) ;
58+
59+ Assert . True ( events . Count > 0 , "events.Count should be > 0" ) ;
60+ foreach ( EventWrittenEventArgs ev in events )
61+ {
62+ Assert . True ( ev . Payload . Count >= 3 ) ;
63+ Assert . NotNull ( ev . Payload [ 0 ] ) ;
64+ Assert . NotNull ( ev . Payload [ 1 ] ) ;
65+ Assert . NotNull ( ev . Payload [ 2 ] ) ;
66+ }
4767 }
48- catch ( Exception e )
49- {
50- throw new SkipTestException ( $ "GetHostEntry failed unexpectedly: { e . Message } ") ;
51- }
52- } ) ;
53-
54- Assert . True ( events . Count > 0 , "events.Count should be > 0" ) ;
55- foreach ( EventWrittenEventArgs ev in events )
56- {
57- Assert . True ( ev . Payload . Count >= 3 ) ;
58- Assert . NotNull ( ev . Payload [ 0 ] ) ;
59- Assert . NotNull ( ev . Payload [ 1 ] ) ;
60- Assert . NotNull ( ev . Payload [ 2 ] ) ;
61- }
68+ } ) . Dispose ( ) ;
69+ }
70+ catch ( Exception ex ) when ( ex . ToString ( ) . Contains ( nameof ( SkipTestException ) , StringComparison . Ordinal ) )
71+ {
72+ throw new SkipTestException ( ex . ToString ( ) ) ;
6273 }
6374 }
6475
65- [ ConditionalFact ]
66- public async Task GetHostEntryAsync_InvalidHost_LogsError ( )
76+ [ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
77+ public void GetHostEntryAsync_InvalidHost_LogsError ( )
6778 {
68- using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Error ) )
79+ try
6980 {
70- var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
71-
72- await listener . RunWithCallbackAsync ( ev => events . Enqueue ( ev ) , async ( ) =>
81+ RemoteExecutor . Invoke ( static async ( ) =>
7382 {
74- try
75- {
76- await Dns . GetHostEntryAsync ( Configuration . Sockets . InvalidHost ) . ConfigureAwait ( false ) ;
77- throw new SkipTestException ( "GetHostEntryAsync should fail but it did not." ) ;
78- }
79- catch ( SocketException e ) when ( e . SocketErrorCode == SocketError . HostNotFound )
83+ using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Error ) )
8084 {
81- await WaitForErrorEventAsync ( events ) ;
85+ var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
86+
87+ await listener . RunWithCallbackAsync ( ev => events . Enqueue ( ev ) , async ( ) =>
88+ {
89+ try
90+ {
91+ await Dns . GetHostEntryAsync ( Configuration . Sockets . InvalidHost ) . ConfigureAwait ( false ) ;
92+ throw new SkipTestException ( "GetHostEntryAsync should fail but it did not." ) ;
93+ }
94+ catch ( SocketException e ) when ( e . SocketErrorCode == SocketError . HostNotFound )
95+ {
96+ await WaitForErrorEventAsync ( events ) ;
97+ }
98+ catch ( Exception e )
99+ {
100+ throw new SkipTestException ( $ "GetHostEntryAsync failed unexpectedly: { e . Message } ") ;
101+ }
102+ } ) . ConfigureAwait ( false ) ;
103+
104+ Assert . True ( events . Count > 0 , "events.Count should be > 0" ) ;
105+ foreach ( EventWrittenEventArgs ev in events )
106+ {
107+ Assert . True ( ev . Payload . Count >= 3 ) ;
108+ Assert . NotNull ( ev . Payload [ 0 ] ) ;
109+ Assert . NotNull ( ev . Payload [ 1 ] ) ;
110+ Assert . NotNull ( ev . Payload [ 2 ] ) ;
111+ }
82112 }
83- catch ( Exception e )
84- {
85- throw new SkipTestException ( $ "GetHostEntryAsync failed unexpectedly: { e . Message } ") ;
86- }
87- } ) . ConfigureAwait ( false ) ;
88-
89- Assert . True ( events . Count > 0 , "events.Count should be > 0" ) ;
90- foreach ( EventWrittenEventArgs ev in events )
91- {
92- Assert . True ( ev . Payload . Count >= 3 ) ;
93- Assert . NotNull ( ev . Payload [ 0 ] ) ;
94- Assert . NotNull ( ev . Payload [ 1 ] ) ;
95- Assert . NotNull ( ev . Payload [ 2 ] ) ;
96- }
113+ } ) . Dispose ( ) ;
114+ }
115+ catch ( Exception ex ) when ( ex . ToString ( ) . Contains ( nameof ( SkipTestException ) , StringComparison . Ordinal ) )
116+ {
117+ throw new SkipTestException ( ex . ToString ( ) ) ;
97118 }
98119
99120 static async Task WaitForErrorEventAsync ( ConcurrentQueue < EventWrittenEventArgs > events )
@@ -110,32 +131,42 @@ static async Task WaitForErrorEventAsync(ConcurrentQueue<EventWrittenEventArgs>
110131 }
111132 }
112133
113- [ ConditionalFact ]
134+ [ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
114135 public void GetHostEntry_ValidName_NoErrors ( )
115136 {
116- using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Verbose ) )
137+ try
117138 {
118- var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
119-
120- listener . RunWithCallback ( ev => events . Enqueue ( ev ) , ( ) =>
139+ RemoteExecutor . Invoke ( static ( ) =>
121140 {
122- try
123- {
124- Dns . GetHostEntryAsync ( "localhost" ) . GetAwaiter ( ) . GetResult ( ) ;
125- Dns . GetHostEntryAsync ( IPAddress . Loopback ) . GetAwaiter ( ) . GetResult ( ) ;
126- Dns . GetHostEntry ( "localhost" ) ;
127- Dns . GetHostEntry ( IPAddress . Loopback ) ;
128- }
129- catch ( Exception e )
141+ using ( var listener = new TestEventListener ( "Private.InternalDiagnostics.System.Net.NameResolution" , EventLevel . Verbose ) )
130142 {
131- throw new SkipTestException ( $ "Localhost lookup failed unexpectedly: { e . Message } ") ;
143+ var events = new ConcurrentQueue < EventWrittenEventArgs > ( ) ;
144+
145+ listener . RunWithCallback ( ev => events . Enqueue ( ev ) , ( ) =>
146+ {
147+ try
148+ {
149+ Dns . GetHostEntryAsync ( "localhost" ) . GetAwaiter ( ) . GetResult ( ) ;
150+ Dns . GetHostEntryAsync ( IPAddress . Loopback ) . GetAwaiter ( ) . GetResult ( ) ;
151+ Dns . GetHostEntry ( "localhost" ) ;
152+ Dns . GetHostEntry ( IPAddress . Loopback ) ;
153+ }
154+ catch ( Exception e )
155+ {
156+ throw new SkipTestException ( $ "Localhost lookup failed unexpectedly: { e . Message } ") ;
157+ }
158+ } ) ;
159+
160+ // We get some traces.
161+ Assert . True ( events . Count ( ) > 0 ) ;
162+ // No errors or warning for successful query.
163+ Assert . True ( events . Count ( ev => ( int ) ev . Level > ( int ) EventLevel . Informational ) == 0 ) ;
132164 }
133- } ) ;
134-
135- // We get some traces.
136- Assert . True ( events . Count ( ) > 0 ) ;
137- // No errors or warning for successful query.
138- Assert . True ( events . Count ( ev => ( int ) ev . Level > ( int ) EventLevel . Informational ) == 0 ) ;
165+ } ) . Dispose ( ) ;
166+ }
167+ catch ( Exception ex ) when ( ex . ToString ( ) . Contains ( nameof ( SkipTestException ) , StringComparison . Ordinal ) )
168+ {
169+ throw new SkipTestException ( ex . ToString ( ) ) ;
139170 }
140171 }
141172 }
0 commit comments