public void IsSampled_SpanContextDebug()
        {
            var rateSampler  = new RateSampler(0f);
            var traceContext = _fixture.Create <SpanContext>();

            traceContext.Debug   = true;
            traceContext.Sampled = null;

            var sampled = rateSampler.IsSampled(traceContext);

            Assert.True(sampled);
        }
        public void IsSampled_NeverSample(float rate)
        {
            var rateSampler = new RateSampler(rate);

            for (var i = 0; i < 1000; i++)
            {
                var traceContext = _fixture.Create <SpanContext>();
                traceContext.Debug   = false;
                traceContext.Sampled = null;

                var sampled = rateSampler.IsSampled(traceContext);
                Assert.False(sampled);
            }
        }
        public void IsSampled_SpecificSampleRate(float rate)
        {
            var rateSampler = new RateSampler(rate);
            var decisions   = new List <bool>();

            for (var i = 0; i < 10000; i++)
            {
                var traceContext = _fixture.Create <SpanContext>();
                traceContext.Debug   = false;
                traceContext.Sampled = null;

                var sampled = rateSampler.IsSampled(traceContext);
                decisions.Add(sampled);
            }

            var expectedSampleCount = rate * 10000;
            var sampleDecisions     = decisions.Where(d => d);

            Assert.Equal(expectedSampleCount, sampleDecisions.Count());
        }
        public void IsSampled_SamplingDecisionAlreadyMade(float rate, bool decision)
        {
            var rateSampler = new RateSampler(rate);

            for (var i = 0; i < 1000; i++)
            {
                var traceContext = _fixture.Create <SpanContext>();
                traceContext.Debug   = false;
                traceContext.Sampled = decision;

                var sampled = rateSampler.IsSampled(traceContext);

                if (decision)
                {
                    Assert.True(sampled);
                }
                else
                {
                    Assert.False(sampled);
                }
            }
        }