<commit_before>﻿using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using RawRabbit.Common;
using RawRabbit.IntegrationTests.TestMessages;
using RawRabbit.vNext;
using Xunit;

namespace RawRabbit.IntegrationTests.SimpleUse
{
	public class MultipleRequestsTests
	{
		[Fact]
		public async void Should_Just_Work()
		{
			/* Setup */
			const int numberOfCalls = 10000;
			var array = new Task[numberOfCalls];
			var requester = BusClientFactory.CreateDefault();
			var responder = BusClientFactory.CreateDefault();
			responder.RespondAsync<FirstRequest, FirstResponse>((req, i) =>
				Task.FromResult(new FirstResponse { Infered = Guid.NewGuid() })
			);

			/* Test */
			var sw = new Stopwatch();
			sw.Start();
			for (var i = 0; i < numberOfCalls; i++)
			{
				var response = requester.RequestAsync<FirstRequest, FirstResponse>();
				array[i] =response;
			}
			Task.WaitAll(array);
			sw.Stop();
			var ids = array
				.OfType<Task<FirstResponse>>()
				.Select(b => b.Result.Infered)
				.Where(id => id != Guid.Empty)
				.Distinct()
				.ToList();

			/* Assert */
			Assert.Equal(numberOfCalls, ids.Count);
		}
	}
}<commit_msg>Add test for multiple types of multiple requests<commit_after>﻿using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using RawRabbit.Common;
using RawRabbit.IntegrationTests.TestMessages;
using RawRabbit.vNext;
using Xunit;

namespace RawRabbit.IntegrationTests.SimpleUse
{
	public class MultipleRequestsTests
	{
		[Fact]
		public async void Should_Just_Work()
		{
			/* Setup */
			const int numberOfCalls = 10000;
			var array = new Task[numberOfCalls];
			var requester = BusClientFactory.CreateDefault();
			var responder = BusClientFactory.CreateDefault();
			responder.RespondAsync<FirstRequest, FirstResponse>((req, i) =>
				Task.FromResult(new FirstResponse { Infered = Guid.NewGuid() })
			);

			/* Test */
			var sw = new Stopwatch();
			sw.Start();
			for (var i = 0; i < numberOfCalls; i++)
			{
				var response = requester.RequestAsync<FirstRequest, FirstResponse>();
				array[i] =response;
			}
			Task.WaitAll(array);
			sw.Stop();
			var ids = array
				.OfType<Task<FirstResponse>>()
				.Select(b => b.Result.Infered)
				.Where(id => id != Guid.Empty)
				.Distinct()
				.ToList();

			/* Assert */
			Assert.Equal(numberOfCalls, ids.Count);
		}

		[Fact]
		public async void Should_Work_For_Multiple_Types()
		{
			/* Setup */
			const int numberOfCalls = 10000;
			var firstResponseTasks = new Task[numberOfCalls];
			var secondResponseTasks = new Task[numberOfCalls];
			var requester = BusClientFactory.CreateDefault();
			var responder = BusClientFactory.CreateDefault();
			responder.RespondAsync<FirstRequest, FirstResponse>((req, i) =>
				Task.FromResult(new FirstResponse { Infered = Guid.NewGuid() })
			);
			responder.RespondAsync<SecondRequest, SecondResponse>((request, context) => 
				Task.FromResult(new SecondResponse {  Source = Guid.NewGuid()})
			);

			/* Test */
			for (var i = 0; i < numberOfCalls; i++)
			{
				var firstResponse = requester.RequestAsync<FirstRequest, FirstResponse>();
				var secondResponse = requester.RequestAsync<SecondRequest, SecondResponse>();
				firstResponseTasks[i] = firstResponse;
				secondResponseTasks[i] = secondResponse;
			}
			Task.WaitAll(firstResponseTasks.Concat(secondResponseTasks).ToArray());
			var firstIds = firstResponseTasks
				.OfType<Task<FirstResponse>>()
				.Select(b => b.Result.Infered)
				.Where(id => id != Guid.Empty)
				.Distinct()
				.ToList();
			var secondIds = secondResponseTasks
				.OfType<Task<SecondResponse>>()
				.Select(b => b.Result.Source)
				.Where(id => id != Guid.Empty)
				.Distinct()
				.ToList();
			/* Assert */
			Assert.Equal(numberOfCalls, firstIds.Count);
			Assert.Equal(numberOfCalls, secondIds.Count);
		}
	}
}
{'fraction_non_alphanumeric': 0.12938816449348045, 'fraction_numerical': 0.004513540621865597, 'mean_word_length': 3.8824969400244798, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6125763', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1255, 'n_words': 267}