public void DebouncerDebounces() { const int numRepeats = 300; const int debounceMs = 1; var counter = 0; var testedDebouncer = new ActiveDebouncer { DebounceMilliseconds = debounceMs }; void actionToDebounce() { ++counter; } var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < numRepeats; ++i) { testedDebouncer.Debounce(actionToDebounce); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds < debounceMs) { Assert.True(counter < numRepeats); } else if (stopwatch.ElapsedMilliseconds * 2 < debounceMs) { Assert.True(counter > 0); } }
public void DebouncerDefault() { var testedDebouncer = new ActiveDebouncer { DebounceMilliseconds = 100 }; Assert.Equal(100, testedDebouncer.DebounceMilliseconds); testedDebouncer = new ActiveDebouncer(); Assert.Equal(1000, testedDebouncer.DebounceMilliseconds); }
private static void Main(string[] args) { Console.WriteLine("Hello in Active Debouncer test harness! " + "This is the load test. The file logger will be spammed with the number of messages (random GUIDs) you choose from multiple threads." + " The debouncer role is to keep the messaged queued in memory and not flush immidiatly. How many messages would you like to send from the thread pool?"); Console.Write("Number of messages: "); int validInteger = GetNaturalInt(); if (validInteger > 100000) { Console.Write(" This can take a while:)"); } Console.WriteLine(); var file = new FileInfo(Path.ChangeExtension(Path.GetRandomFileName(), "txt")); Console.WriteLine($"The contents will be written to {file.FullName}."); var watch = Stopwatch.StartNew(); var fileLogger = new FileLoggerBase(file.FullName); using (var debouncer = new ActiveDebouncer()) using (var wrapper = new QueuedLoggerWrapper(fileLogger, debouncer)) { Parallel.For(0, validInteger, x => { wrapper.LogInfo(Guid.NewGuid().ToString()); }); watch.Stop(); Console.WriteLine($"Finished in {watch.Elapsed} with {wrapper.Failures} failures, after {wrapper.Requests} log requests"); } Console.WriteLine("Open file? y/n"); var key = Console.ReadKey(); if (key.KeyChar == 'y') { using (var process = Process.Start(new ProcessStartInfo { FileName = fileLogger.OutputFile.FullName, UseShellExecute = true })) { } } Console.WriteLine(); Console.WriteLine("Delete file? y/n"); key = Console.ReadKey(); if (key.KeyChar == 'y') { fileLogger.OutputFile.Delete(); } }
public void NeedsDisposingAlwaysReturnsTrue() { var testedDebouncer = new ActiveDebouncer(); Assert.True(testedDebouncer.NeedsDisposing); }