|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
| 4 | +using Microsoft.DotNet.RemoteExecutor; |
| 5 | +using System.Diagnostics.Tracing; |
4 | 6 | using System.Runtime.InteropServices; |
| 7 | +using System.Text; |
5 | 8 | using System.Threading; |
6 | 9 | using System.Threading.Tasks; |
7 | 10 | using Xunit; |
@@ -228,38 +231,61 @@ async Task VerifyAccept(TcpListener listener) |
228 | 231 | } |
229 | 232 | } |
230 | 233 |
|
231 | | - [Fact] |
232 | | - public async Task ReadAsyncTest() |
| 234 | + internal sealed class RuntimeEventListener : EventListener |
233 | 235 | { |
234 | | - async Task StartListenerAsync() |
| 236 | + protected override void OnEventSourceCreated(EventSource source) |
235 | 237 | { |
236 | | - TcpListener listener = new TcpListener(IPAddress.Loopback, 0); |
237 | | - listener.Start(); |
238 | | - Tcp client = await listener.AcceptTcpClientAsync(); |
239 | | - using (NetworkStream stream = client.GetStream()) |
| 238 | + if (source.Name.Equals("Microsoft-Windows-DotNETRuntime")) |
240 | 239 | { |
241 | | - byte[] buffer = new byte[1024]; |
242 | | - int bytesRead; |
243 | | - while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0); |
| 240 | + EnableEvents(source, EventLevel.Verbose, (EventKeywords)0x10000); |
244 | 241 | } |
245 | | - listener.Stop(); |
246 | 242 | } |
| 243 | + } |
247 | 244 |
|
248 | | - async Task StartClientAsync() |
| 245 | + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] |
| 246 | + public void ReadAsyncTest() |
| 247 | + { |
| 248 | + RemoteExecutor.Invoke(async () => |
249 | 249 | { |
250 | | - TcpClient client = new TcpClient(IPAddress.Loopback, 0); |
251 | | - using (NetworkStream stream = client.GetStream()) |
| 250 | + using (RuntimeEventListener eventListener = new RuntimeEventListener()) |
252 | 251 | { |
253 | | - byte[] data = Encoding.UTF8.GetBytes(new string('*', 1 << 22)); |
254 | | - await Task.Delay(10); |
255 | | - await stream.WriteAsync(data, 0, data.Length); |
| 252 | + Task.Run(() => Console.WriteLine(Environment.StackTrace)).Wait(); |
| 253 | + TaskCompletionSource<int> portTcs = new TaskCompletionSource<int>(); |
| 254 | + async Task StartListenerAsync() |
| 255 | + { |
| 256 | + TcpListener listener = new TcpListener(IPAddress.Loopback, 0); |
| 257 | + listener.Start(); |
| 258 | + int port = ((IPEndPoint)listener.LocalEndpoint).Port; |
| 259 | + portTcs.SetResult(port); |
| 260 | + TcpClient client = await listener.AcceptTcpClientAsync(); |
| 261 | + using (NetworkStream stream = client.GetStream()) |
| 262 | + { |
| 263 | + byte[] buffer = new byte[1024]; |
| 264 | + int bytesRead; |
| 265 | + while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0); |
| 266 | + } |
| 267 | + listener.Stop(); |
| 268 | + } |
| 269 | + |
| 270 | + async Task StartClientAsync() |
| 271 | + { |
| 272 | + int port = await portTcs.Task; |
| 273 | + using (TcpClient client = new TcpClient(new IPEndPoint(IPAddress.Loopback, 0))) |
| 274 | + { |
| 275 | + await client.ConnectAsync(IPAddress.Loopback, port); |
| 276 | + using (NetworkStream stream = client.GetStream()) |
| 277 | + { |
| 278 | + byte[] data = Encoding.UTF8.GetBytes(new string('*', 1 << 26)); |
| 279 | + await stream.WriteAsync(data, 0, data.Length); |
| 280 | + } |
| 281 | + } |
| 282 | + } |
| 283 | + |
| 284 | + Task listenerTask = StartListenerAsync(); |
| 285 | + Task clientTask = StartClientAsync(); |
| 286 | + await Task.WhenAll(listenerTask, clientTask); |
256 | 287 | } |
257 | | - client.Close(); |
258 | | - } |
259 | | - |
260 | | - Task.Run(() => Console.WriteLine(Environment.StackTrace)).Wait(); |
261 | | - await StartListenerAsync(); |
262 | | - await StartClientAsync(); |
| 288 | + }).Dispose(); |
263 | 289 | } |
264 | 290 |
|
265 | 291 | [Fact] |
|
0 commit comments