<commit_before>﻿namespace Flower.Tests.WorkRunners
{
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using Flower.WorkRunners;
    using Flower.Works;
    using Xunit;

    public class ThreadPoolWorkRunnerTests 
    {
        [Theory]
        [InlineData(200, 100)]
        [InlineData(1000, 5)]
        public async void ThreadPoolRunnerExecutesAllWorksInParallel(int delayInMilliseconds, int workCount)
        {
            // Arrange
            var countdown = new CountdownEvent(workCount);
            var workRunner = new ThreadPoolWorkRunner();
            var workRunnerSnapshots = new ConcurrentBag<WorkRunnerSnapshot>();

            // Act
            for (var i = 0; i < workCount; i++)
            {
                await
                    workRunner.Submit(
                        new MockExecutableWork(countdown, delayInMilliseconds, workRunnerSnapshots, workRunner));
            }

            // Assert
            countdown.Wait(TimeSpan.FromSeconds(20));
            Assert.Equal(workCount, workRunnerSnapshots.Count);
            Assert.True(workRunnerSnapshots.Select(state => state.PendingWorks.Count).All(count => count == 0));
            foreach (var executingWorkCount in workRunnerSnapshots.Select(state => state.ExecutingWorks.Count))
            {
                Assert.InRange(executingWorkCount, 1, workCount);
            }
            Assert.Equal(0, workRunner.ExecutingWorks.Count());
        }<commit_msg>Add a delay to allow successful unit testing on CI server.<commit_after>﻿namespace Flower.Tests.WorkRunners
{
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using Flower.WorkRunners;
    using Flower.Works;
    using Xunit;

    public class ThreadPoolWorkRunnerTests 
    {
        [Theory]
        [InlineData(200, 100)]
        [InlineData(1000, 5)]
        public async void ThreadPoolRunnerExecutesAllWorksInParallel(int delayInMilliseconds, int workCount)
        {
            // Arrange
            var countdown = new CountdownEvent(workCount);
            var workRunner = new ThreadPoolWorkRunner();
            var workRunnerSnapshots = new ConcurrentBag<WorkRunnerSnapshot>();

            // Act
            for (var i = 0; i < workCount; i++)
            {
                await
                    workRunner.Submit(
                        new MockExecutableWork(countdown, delayInMilliseconds, workRunnerSnapshots, workRunner));
            }

            // Assert
            countdown.Wait(TimeSpan.FromSeconds(20));
            await Task.Delay(100); // Allow background thread to remove the work from workRunner
            Assert.Equal(workCount, workRunnerSnapshots.Count);
            Assert.True(workRunnerSnapshots.Select(state => state.PendingWorks.Count).All(count => count == 0));
            foreach (var executingWorkCount in workRunnerSnapshots.Select(state => state.ExecutingWorks.Count))
            {
                Assert.InRange(executingWorkCount, 1, workCount);
            }
            Assert.Equal(0, workRunner.ExecutingWorks.Count());
        }
{'fraction_non_alphanumeric': 0.08649789029535865, 'fraction_numerical': 0.011151295961422544, 'mean_word_length': 2.1944177093359, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3396832', 'n_tokens_mistral': 896, 'n_tokens_neox': 854, 'n_words': 185}