public void WhenFileIsntAtBackgroundQueueAndTriedToBeQueued_ThenQueue()
        {
            var now      = DateTime.UtcNow;
            var queue    = new AnalyzerWorkQueue(new TestLoggerFactory(), utcNow: () => now, timeoutForPendingWorkMs: 10 * 1000);
            var document = CreateTestDocumentId();

            queue.QueueDocumentForeground(document);

            now = PassOverThrotlingPeriod(now);

            Assert.Equal(document, queue.TakeWork(AnalyzerWorkType.Foreground).Single());
        }
        public void WhenSingleFileIsQueued_ThenPromoteItFromBackgroundQueueToForeground()
        {
            var now      = DateTime.UtcNow;
            var queue    = new AnalyzerWorkQueue(new TestLoggerFactory(), utcNow: () => now, timeoutForPendingWorkMs: 10 * 1000);
            var document = CreateTestDocumentId();

            queue.PutWork(new[] { document }, AnalyzerWorkType.Background);

            queue.QueueDocumentForeground(document);

            now = PassOverThrotlingPeriod(now);

            Assert.NotEmpty(queue.TakeWork(AnalyzerWorkType.Foreground));
        }
Ejemplo n.º 3
0
        private async Task <ImmutableArray <DocumentDiagnostics> > GetDiagnosticsByDocument(ImmutableArray <Document> documents, bool waitForDocuments)
        {
            if (documents.IsDefaultOrEmpty)
            {
                return(ImmutableArray <DocumentDiagnostics> .Empty);
            }

            ImmutableArray <DocumentDiagnostics> .Builder resultsBuilder = ImmutableArray.CreateBuilder <DocumentDiagnostics>(documents.Length);
            resultsBuilder.Count = documents.Length;

            bool foundAll = true;

            for (int i = 0; i < documents.Length; i++)
            {
                if (_currentDiagnosticResultLookup.TryGetValue(documents[i], out var diagnostics))
                {
                    resultsBuilder[i] = diagnostics;
                }
                else
                {
                    _workQueue.QueueDocumentForeground(documents[i]);
                    foundAll = false;
                }
            }

            if (foundAll)
            {
                return(resultsBuilder.MoveToImmutable());
            }

            await _workQueue.WaitForegroundWorkComplete();

            for (int i = 0; i < documents.Length; i++)
            {
                if (_currentDiagnosticResultLookup.TryGetValue(documents[i], out var diagnostics))
                {
                    resultsBuilder[i] = diagnostics;
                }
                else
                {
                    Debug.Fail("Should have diagnostics after waiting for work");
                    resultsBuilder[i] = new DocumentDiagnostics(documents[i], ImmutableArray <Diagnostic> .Empty);
                }
            }

            return(resultsBuilder.MoveToImmutable());
        }