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; } }
protected virtual void Dispose(bool disposing) { if (!_isDisposed) { _isDisposed = true; if (disposing) { lock (_listenerLock) { if (_listener != null) { _listener.Dispose(); _listener = null; } } } } }
public InterpreterView(IPythonInterpreterFactory interpreter, string name, bool isDefault) { Interpreter = interpreter; Name = name; SubName = string.Empty; Identifier = _identifier = AnalyzerStatusListener.GetIdentifier(interpreter); var withDb = interpreter as IPythonInterpreterFactoryWithDatabase; if (withDb != null) { CanRefresh = File.Exists(interpreter.Configuration.InterpreterPath); withDb.IsCurrentChanged += Interpreter_IsCurrentChanged; IsCurrent = withDb.IsCurrent; IsCurrentReason = withDb.GetFriendlyIsCurrentReason(CultureInfo.CurrentUICulture); } IsRunning = false; IsDefault = isDefault; }
public void SendUpdates() { Dictionary <string, AnalysisProgress> results = null; using (var ready = new AutoResetEvent(false)) using (var listener = new AnalyzerStatusListener(r => { results = r; ready.Set(); })) { ready.Reset(); 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 sender1 = new AnalyzerStatusUpdater("SendUpdates1")) using (var sender2 = new AnalyzerStatusUpdater("SendUpdates2")) { // Block until workers have started sender1.WaitForWorkerStarted(); sender1.ThrowPendingExceptions(); sender2.WaitForWorkerStarted(); sender2.ThrowPendingExceptions(); ready.Reset(); listener.RequestUpdate(); ready.WaitOne(); Assert.IsNotNull(results); AssertUtil.ContainsAtLeast(results.Keys, "SendUpdates1", "SendUpdates2"); Assert.AreEqual(int.MaxValue, results["SendUpdates1"].Progress, "SendUpdates1.Progress not initialized to MaxValue"); Assert.AreEqual(0, results["SendUpdates1"].Maximum, "SendUpdates1.Maximum not initialized to 0"); Assert.AreEqual(string.Empty, results["SendUpdates1"].Message, "SendUpdates1.Message not initialized to empty"); Assert.AreEqual(int.MaxValue, results["SendUpdates2"].Progress, "SendUpdates2.Progress not initialized to MaxValue"); Assert.AreEqual(0, results["SendUpdates2"].Maximum, "SendUpdates2.Maximum not initialized to 0"); Assert.AreEqual(string.Empty, results["SendUpdates2"].Message, "SendUpdates2.Message not initialized to empty"); sender1.UpdateStatus(100, 200, 300, "Message1"); sender1.FlushQueue(TimeSpan.FromSeconds(1.0)); ready.Reset(); listener.RequestUpdate(); ready.WaitOne(); Assert.AreEqual(100, results["SendUpdates1"].Progress, "SendUpdates1.Progress not set to 100"); Assert.AreEqual(200, results["SendUpdates1"].Maximum, "SendUpdates1.Maximum not set to 200"); Assert.AreEqual(300, results["SendUpdates1"].Seconds, "SendUpdates1.Seconds not set to 300"); Assert.AreEqual("Message1", results["SendUpdates1"].Message, "SendUpdates1.Message not set"); Assert.AreEqual(int.MaxValue, results["SendUpdates2"].Progress, "SendUpdates2.Progress changed from MaxValue"); Assert.AreEqual(0, results["SendUpdates2"].Maximum, "SendUpdates2.Maximum changed from 0"); Assert.AreEqual(string.Empty, results["SendUpdates2"].Message, "SendUpdates2.Message changed from empty"); sender2.UpdateStatus(1000, 2000, 3000, "Message2"); sender2.FlushQueue(TimeSpan.FromSeconds(1.0)); ready.Reset(); listener.RequestUpdate(); ready.WaitOne(); Assert.AreEqual(100, results["SendUpdates1"].Progress, "SendUpdates1.Progress changed from 100"); Assert.AreEqual(200, results["SendUpdates1"].Maximum, "SendUpdates1.Maximum changed from 200"); Assert.AreEqual(300, results["SendUpdates1"].Seconds, "SendUpdates1.Seconds changed from 300"); Assert.AreEqual("Message1", results["SendUpdates1"].Message, "SendUpdates1.Message changed"); Assert.AreEqual(1000, results["SendUpdates2"].Progress, "SendUpdates2.Progress not set to 1000"); Assert.AreEqual(2000, results["SendUpdates2"].Maximum, "SendUpdates2.Maximum not set to 2000"); Assert.AreEqual(3000, results["SendUpdates2"].Seconds, "SendUpdates2.Seconds not set to 3000"); Assert.AreEqual("Message2", results["SendUpdates2"].Message, "SendUpdates2.Message not set"); } Thread.Sleep(100); // allow updaters to terminate ready.Reset(); listener.RequestUpdate(); ready.WaitOne(); Assert.IsNotNull(results); if (results.Count > 0) { Console.WriteLine("WARNING: {0} results exist at end of test", results.Count); Console.WriteLine("Keys are:"); foreach (var key in results.Keys) { Console.WriteLine(" {0}", key); } } Assert.IsFalse(results.ContainsKey("SendUpdates1"), "results were not cleaned up"); Assert.IsFalse(results.ContainsKey("SendUpdates2"), "results were not cleaned up"); } }
public void InitializeWithoutCrashing() { using (var updater = new AnalyzerStatusUpdater("InitializeWithoutCrashing")) { } using (var updater = new AnalyzerStatusListener(x => { })) { } }