public async void CanWaitForCounter() { var metrics = new InMemoryMetricsClient(); metrics.StartDisplayingStats(TimeSpan.FromMilliseconds(50), _writer); Task.Run(() => { Thread.Sleep(50); metrics.Counter("Test"); metrics.Counter("Test"); }); var success = await metrics.WaitForCounterAsync("Test", TimeSpan.FromMilliseconds(500), 2); Assert.True(success); Task.Run(() => { Thread.Sleep(50); metrics.Counter("Test"); }); success = await metrics.WaitForCounterAsync("Test", TimeSpan.FromMilliseconds(500)); Assert.True(success); success = await metrics.WaitForCounterAsync("Test", TimeSpan.FromMilliseconds(100)); Assert.False(success); Task.Run(() => { Thread.Sleep(50); metrics.Counter("Test", 2); }); success = await metrics.WaitForCounterAsync("Test", TimeSpan.FromMilliseconds(500), 2); Assert.True(success); success = await metrics.WaitForCounterAsync("Test", () => metrics.CounterAsync("Test"), TimeSpan.FromMilliseconds(500)); Assert.True(success); Task.Run(() => { Thread.Sleep(50); metrics.Counter("Test"); }); success = metrics.WaitForCounter("Test", TimeSpan.FromMilliseconds(500)); Assert.True(success); metrics.DisplayStats(_writer); }
public virtual void CanHandleErrorInWorker() { var queue = GetQueue(retries: 0); if (queue == null) return; var metrics = new InMemoryMetricsClient(); queue.AttachBehavior(new MetricsQueueBehavior<SimpleWorkItem>(metrics)); using (queue) { queue.DeleteQueue(); queue.StartWorking(w => { Debug.WriteLine("WorkAction"); Assert.Equal("Hello", w.Value.Data); throw new ApplicationException(); }); metrics.DisplayStats(_writer); var success = metrics.WaitForCounter("simpleworkitem.hello.abandoned", () => queue.Enqueue(new SimpleWorkItem { Data = "Hello" }), TimeSpan.FromSeconds(1)); metrics.DisplayStats(_writer); Assert.True(success); Assert.Equal(0, queue.GetQueueStats().Completed); Assert.Equal(1, queue.GetQueueStats().Errors); Assert.Equal(1, queue.GetQueueStats().Deadletter); } }