Beispiel #1
0
        public async Task OutputDebouncerDoesNotDuplicateOutput()
        {
            TestMessageSender messageSender = new TestMessageSender();
            OutputDebouncer   debouncer     = new OutputDebouncer(messageSender);

            // Send many messages in quick succession to ensure that
            // output is not being duplicated in subsequent events.
            for (int i = 1; i <= 50; i++)
            {
                await SendOutput(debouncer, "Output " + i, true);

                if (i == 25)
                {
                    // Artificially insert a delay to force another event
                    await Task.Delay(OutputDebouncer.OutputFlushInterval + 100);
                }
            }

            // Wait for the final event to be written
            await Task.Delay(OutputDebouncer.OutputFlushInterval + 100);

            // Ensure that the two events start with the correct lines
            Assert.Equal(2, messageSender.OutputEvents.Count);
            Assert.Equal("Output 1", messageSender.OutputEvents[0].Output.Split('\n')[0].Trim('\r'));
            Assert.Equal("Output 26", messageSender.OutputEvents[1].Output.Split('\n')[0].Trim('\r'));
        }
Beispiel #2
0
        public async Task OutputDebouncerAggregatesOutputEvents()
        {
            TestMessageSender messageSender = new TestMessageSender();
            OutputDebouncer   debouncer     = new OutputDebouncer(messageSender);

            await SendOutput(debouncer, "This ");
            await SendOutput(debouncer, "is a ");
            await SendOutput(debouncer, "test", true);
            await SendOutput(debouncer, "Another line");

            // Make sure no output events have been written yet
            Assert.Empty(messageSender.OutputEvents);

            // Wait for the output to be flushed
            await Task.Delay(OutputDebouncer.OutputFlushInterval + 100);

            // Write some more output after the first flush
            await SendOutput(debouncer, "Another test line", true);
            await SendOutput(debouncer, "for great justice");

            // Assert that there's only one event with the expected string
            Assert.Single(messageSender.OutputEvents);
            Assert.Equal(
                TestUtilities.NormalizeNewlines("This is a test\nAnother line"),
                messageSender.OutputEvents[0].Output);

            // Wait for the next output to be flushed
            await Task.Delay(OutputDebouncer.OutputFlushInterval + 100);

            // Assert that there's only one event with the expected string
            Assert.Equal(2, messageSender.OutputEvents.Count);
            Assert.Equal(
                TestUtilities.NormalizeNewlines("Another test line\nfor great justice"),
                messageSender.OutputEvents[1].Output);
        }