Beispiel #1
0
		public async Task Listens()
		{
			ServerSettings settings = GetDefaultSettings();
			using (CancellationTokenSource cancellation = new CancellationTokenSource())
			{
				ServerHost host = new ServerHost(settings);
				Task serveForever = host.ServeForeverAsync(cancellation.Token);

				Task test = Task.Run(
					async () =>
					{
						var getTasks = host.Endpoints.Select(ep => _client.GetAsync(ep)).ToList();
						foreach (var task in getTasks)
						{
							using (HttpResponseMessage response = await task)
							{
								_output.WriteLine($"Response from {response.RequestMessage.RequestUri}");
								_output.WriteLine(response.ToString());

								Assert.True(response.IsSuccessStatusCode);
								Assert.Equal(HttpStatusCode.OK, response.StatusCode);
							}
						}
					});

				await Task.WhenAny(test, serveForever);
			}
		}
Beispiel #2
0
		public async Task HandlesManyRequests(Int64 requestCount)
		{
			ServerSettings settings = GetDefaultSettings();
			using (CancellationTokenSource cancellation = new CancellationTokenSource())
			{
				ServerHost host = new ServerHost(settings);
				Task serveForever = host.ServeForeverAsync(cancellation.Token);

				Task test = Task.Run(
					async () =>
					{
						var tortureTasks = host.Endpoints.Select(ep => HttpTorturer.TortureAsync(ep, requestCount)).ToList();
						foreach (var task in tortureTasks)
						{
							var result = await task;
							_output.WriteLine(result.ToString());
						}
					});

				await Task.WhenAny(test, serveForever);
			}
		}