<commit_before>﻿using System.Collections.Generic;
using System.Threading;
using Sys = System.Threading.Tasks;
using MSOE.MediaComplete.Lib.Background;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSOE.MediaComplete.Test.Background
{
    [TestClass]
    public class QueueTest
    {
        [TestMethod]
        public void Add_Task_CallsResolveConflicts()
        {
            var mock = new MockTask();
            Queue.Inst.Add(mock);

            Assert.IsTrue(mock.ResolveConflictsCalled, "Mock didn't have its conflicts resolved!");
            Assert.IsTrue(mock.DoCalled, "Mock wasn't run!");
        }

        [TestMethod]
        public void Add_QueueAlreadyRunning_NewTaskRuns()
        {
            var longMock = new MockTask(0, 25000);
            Queue.Inst.Add(longMock);

            var secondMock = new MockTask();
            Queue.Inst.Add(secondMock);

            Assert.IsTrue(secondMock.ResolveConflictsCalled, "Second mock didn't have its conflicts resolved!");
            Assert.IsFalse(secondMock.DoCalled, "Second mock started too early!");

            // Wait for the second task to run
            SpinWait.SpinUntil(() => !secondMock.DoCalled, 30000);
        }

        private class MockTask : Task
        {
            public bool ResolveConflictsCalled { get; private set; }
            public bool DoCalled { get; private set; }
            private readonly int _resolveConflictsDelay;
            private readonly int _doDelay;

            public MockTask(int resolveConflictsDelay = 0, int doDelay = 0)
            {
                ResolveConflictsCalled = false;<commit_msg>MC-111 Fixing test - would fail on low-performance machines<commit_after>﻿using System.Collections.Generic;
using System.Threading;
using Sys = System.Threading.Tasks;
using MSOE.MediaComplete.Lib.Background;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSOE.MediaComplete.Test.Background
{
    [TestClass]
    public class QueueTest
    {
        [TestMethod]
        public void Add_Task_CallsResolveConflicts()
        {
            var mock = new MockTask();
            Queue.Inst.Add(mock);

            Assert.IsTrue(mock.ResolveConflictsCalled, "Mock didn't have its conflicts resolved!");
            SpinWait.SpinUntil(() => mock.DoCalled, 30000);
        }

        [TestMethod]
        public void Add_QueueAlreadyRunning_NewTaskRuns()
        {
            var longMock = new MockTask(0, 25000);
            Queue.Inst.Add(longMock);

            var secondMock = new MockTask();
            Queue.Inst.Add(secondMock);

            Assert.IsTrue(secondMock.ResolveConflictsCalled, "Second mock didn't have its conflicts resolved!");
            Assert.IsFalse(secondMock.DoCalled, "Second mock started too early!");

            // Wait for the second task to run
            SpinWait.SpinUntil(() => secondMock.DoCalled, 30000);
        }

        private class MockTask : Task
        {
            public bool ResolveConflictsCalled { get; private set; }
            public bool DoCalled { get; private set; }
            private readonly int _resolveConflictsDelay;
            private readonly int _doDelay;

            public MockTask(int resolveConflictsDelay = 0, int doDelay = 0)
            {
                ResolveConflictsCalled = false;
{'fraction_non_alphanumeric': 0.08486307553415588, 'fraction_numerical': 0.01023171832681312, 'mean_word_length': 2.324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3825255', 'n_tokens_mistral': 924, 'n_tokens_neox': 864, 'n_words': 223}