<commit_before>﻿namespace Burble.Tests.throttling_scenarios
{
   using System;
   using System.Linq;
   using System.Net;
   using System.Threading.Tasks;
   using System.Net.Http;
   using System.Threading;
   using Burble.Abstractions;
   using Burble.Throttling;
   using Xunit;
   using Shouldly;

   public class limit_concurrent_requests
   {
      private const int ExpectedMaxConcurrentRequests = 3;
      private const int ExpectedTotalRequests = 7;

      private readonly CountingHttpClient _baseHttpClient;

      public limit_concurrent_requests()
      {
         _baseHttpClient = new CountingHttpClient();
         var httpClient = _baseHttpClient.AddThrottling(new SemaphoneThrottleSync(ExpectedMaxConcurrentRequests));

         var tasks = Enumerable.Range(1, ExpectedTotalRequests).Select(c => httpClient.GetAsync("/ping")).ToArray();
         Task.WhenAll(tasks).Wait(1000);
      }

      [Fact]
      public void should_not_exceed_concurrent_requests()
      {
         _baseHttpClient.MaxConcurrentRequests.ShouldBeLessThanOrEqualTo(ExpectedMaxConcurrentRequests);
      }

      [Fact]
      public void should_handle_all_requests()
      {
         _baseHttpClient.TotalRequests.ShouldBe(ExpectedTotalRequests);
      }

      private class CountingHttpClient : IHttpClient
      {
         private readonly object _lock = new object();

         private int _currentRequests;

         public int MaxConcurrentRequests { get; private set; }

         public int TotalRequests { get; private set; }

         public Uri BaseAddress
         {
            get { throw new NotImplementedException(); }
         }
<commit_msg>Give test time to complete<commit_after>﻿namespace Burble.Tests.throttling_scenarios
{
   using System;
   using System.Linq;
   using System.Net;
   using System.Threading.Tasks;
   using System.Net.Http;
   using System.Threading;
   using Burble.Abstractions;
   using Burble.Throttling;
   using Xunit;
   using Shouldly;

   public class limit_concurrent_requests
   {
      private const int ExpectedMaxConcurrentRequests = 3;
      private const int ExpectedTotalRequests = 7;

      private readonly CountingHttpClient _baseHttpClient;

      public limit_concurrent_requests()
      {
         _baseHttpClient = new CountingHttpClient();
         var httpClient = _baseHttpClient.AddThrottling(new SemaphoneThrottleSync(ExpectedMaxConcurrentRequests));

         var tasks = Enumerable.Range(1, ExpectedTotalRequests).Select(c => httpClient.GetAsync("/ping")).ToArray();
         Task.WhenAll(tasks).Wait(2000);
      }

      [Fact]
      public void should_not_exceed_concurrent_requests()
      {
         _baseHttpClient.MaxConcurrentRequests.ShouldBeLessThanOrEqualTo(ExpectedMaxConcurrentRequests);
      }

      [Fact]
      public void should_handle_all_requests()
      {
         _baseHttpClient.TotalRequests.ShouldBe(ExpectedTotalRequests);
      }

      private class CountingHttpClient : IHttpClient
      {
         private readonly object _lock = new object();

         private int _currentRequests;

         public int MaxConcurrentRequests { get; private set; }

         public int TotalRequests { get; private set; }

         public Uri BaseAddress
         {
            get { throw new NotImplementedException(); }
         }

{'fraction_non_alphanumeric': 0.07127755964965267, 'fraction_numerical': 0.004228329809725159, 'mean_word_length': 2.956989247311828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3522916', 'n_tokens_mistral': 910, 'n_tokens_neox': 908, 'n_words': 196}