Пример #1
0
        public void Can_stop()
        {
            var block = new ManualResetEvent(false);

            RegisterMetrics();

            ThreadPool.QueueUserWorkItem(
                s =>
            {
                var reporter = new SampledFileReporter(Path.GetTempPath(), _metrics);
                reporter.Start(1, TimeUnit.Seconds);
                reporter.Stopped += delegate { block.Set(); };
                Thread.Sleep(2000);
                reporter.Stop();
            });

            block.WaitOne();
        }
Пример #2
0
        public void Can_run_in_background()
        {
            const int ticks = 3;
            var       block = new ManualResetEvent(false);

            RegisterMetrics();

            var directory = Path.GetTempPath();
            var samples   = Directory.GetFiles(directory, "*.sample");

            foreach (var file in samples)
            {
                File.Delete(file);
            }

            ThreadPool.QueueUserWorkItem(
                s =>
            {
                var reporter = new SampledFileReporter(directory, new JsonReportFormatter(_metrics));
                reporter.Start(1, TimeUnit.Seconds);
                while (true)
                {
                    Thread.Sleep(1000);
                    var runs = reporter.Runs;
                    if (runs == ticks)
                    {
                        block.Set();
                        reporter.Stop();
                        reporter.Dispose();
                    }
                }
            });

            block.WaitOne(TimeSpan.FromSeconds(5));
            samples = Directory.GetFiles(directory, "*.sample");
            Assert.GreaterOrEqual(samples.Length, 3);
        }