public void MessageMaximumLength() { Dictionary <string, AnalysisProgress> results = null; using (var ready = new AutoResetEvent(false)) using (var listener = new AnalyzerStatusListener(r => { results = r; ready.Set(); })) { listener.WaitForWorkerStarted(); listener.ThrowPendingExceptions(); // Ensure that updates are being received listener.RequestUpdate(); ready.WaitOne(); Assert.IsNotNull(results); if (results.Count > 0) { ready.Reset(); listener.RequestUpdate(); ready.WaitOne(); Assert.IsNotNull(results); if (results.Count > 0) { Console.WriteLine("WARNING: {0} results received from a previous test", results.Count); Console.WriteLine("Keys are:"); foreach (var key in results.Keys) { Console.WriteLine(" {0}", key); } } } using (var sender = new AnalyzerStatusUpdater("MessageMaximumLength")) { sender.WaitForWorkerStarted(); sender.ThrowPendingExceptions(); // Create a message that is deliberately too long string message = new string('x', AnalyzerStatusUpdater.MAX_MESSAGE_LENGTH * 2); sender.UpdateStatus(0, 0, 0, message); sender.FlushQueue(TimeSpan.FromSeconds(1.0)); listener.RequestUpdate(); ready.WaitOne(); Assert.IsNotNull(results); AssertUtil.Contains(results.Keys, "MessageMaximumLength"); var receivedMessage = results["MessageMaximumLength"].Message; Console.WriteLine("Message: <{0}>", receivedMessage); Assert.AreEqual( AnalyzerStatusUpdater.MAX_MESSAGE_LENGTH, receivedMessage.Length, "Message length was not limited" ); } } }
private void CreateListener() { lock (_listenerLock) { var oldListener = _listener; if (oldListener != null) { oldListener.ThrowPendingExceptions(); oldListener.Dispose(); } var newListener = new AnalyzerStatusListener(Listener_ProgressUpdate, TimeSpan.FromMilliseconds(250)); newListener.ThrowPendingExceptions(); _listener = newListener; _listenerTimeToLive = _listenerDefaultTimeToLive; } }