/// <summary>
        /// Wait for the given number of spans to appear.
        /// </summary>
        /// <param name="count">The expected number of spans.</param>
        /// <param name="timeoutInMilliseconds">The timeout</param>
        /// <param name="operationName">The integration we're testing</param>
        /// <param name="minDateTime">Minimum time to check for spans from</param>
        /// <param name="returnAllOperations">When true, returns every span regardless of operation name</param>
        /// <returns>The list of spans.</returns>
        public IImmutableList <Span> WaitForSpans(
            int count,
            int timeoutInMilliseconds  = 20000,
            string operationName       = null,
            DateTimeOffset?minDateTime = null,
            bool returnAllOperations   = false)
        {
            var deadline      = DateTime.Now.AddMilliseconds(timeoutInMilliseconds);
            var minimumOffset = (minDateTime ?? DateTimeOffset.MinValue).ToUnixTimeNanoseconds();

            IImmutableList <Span> relevantSpans = ImmutableList <Span> .Empty;

            while (DateTime.Now < deadline)
            {
                relevantSpans =
                    Spans
                    .Where(s => SpanFilters.All(shouldReturn => shouldReturn(s)))
                    .Where(s => s.Start > minimumOffset)
                    .ToImmutableList();

                if (relevantSpans.Count(s => operationName == null || s.Name == operationName) >= count)
                {
                    break;
                }

                Thread.Sleep(500);
            }

            foreach (var headers in RequestHeaders)
            {
                // This is the place to check against headers we expect
                AssertHeader(
                    headers,
                    "X-Datadog-Trace-Count",
                    header =>
                {
                    if (int.TryParse(header, out int traceCount))
                    {
                        return(traceCount > 0);
                    }

                    return(false);
                });
            }

            if (!returnAllOperations)
            {
                relevantSpans =
                    relevantSpans
                    .Where(s => operationName == null || s.Name == operationName)
                    .ToImmutableList();
            }

            return(relevantSpans);
        }
Пример #2
0
        /// <summary>
        /// Wait for the given number of spans to appear.
        /// </summary>
        /// <param name="count">The expected number of spans.</param>
        /// <param name="timeoutInMilliseconds">The timeout</param>
        /// <param name="operationName">The integration we're testing</param>
        /// <param name="minDateTime">Minimum time to check for spans from</param>
        /// <param name="returnAllOperations">When true, returns every span regardless of operation name</param>
        /// <param name="operationNameContainsAny">Set of words that need to be present of selected span names</param>
        /// <returns>The list of spans.</returns>
        public IImmutableList <IMockSpan> WaitForSpans(
            int count,
            int timeoutInMilliseconds         = 20000,
            string operationName              = null,
            DateTimeOffset?minDateTime        = null,
            bool returnAllOperations          = false,
            string[] operationNameContainsAny = null)
        {
            var deadline      = DateTime.Now.AddMilliseconds(timeoutInMilliseconds);
            var minimumOffset = (minDateTime ?? DateTimeOffset.MinValue).ToUnixTimeMicroseconds();

            IImmutableList <IMockSpan> relevantSpans = ImmutableList <IMockSpan> .Empty;

            operationNameContainsAny ??= new string[0];
            while (DateTime.Now < deadline)
            {
                relevantSpans =
                    Spans
                    .Where(s => SpanFilters.All(shouldReturn => shouldReturn(s)))
                    .Where(s => s.Start > minimumOffset)
                    .ToImmutableList();

                if (relevantSpans.Count(s => operationNameContainsAny.Any(contains => s.Name.Contains(contains)) || operationName == null || s.Name == operationName) >= count)
                {
                    break;
                }

                Thread.Sleep(500);
            }

            if (!returnAllOperations)
            {
                relevantSpans =
                    relevantSpans
                    .Where(s => operationNameContainsAny.Any(contains => s.Name.Contains(contains)) ||
                           (operationNameContainsAny.Length == 0 && operationName == null) ||
                           s.Name == operationName)
                    .ToImmutableList();
            }

            return(relevantSpans);
        }
    /// <summary>
    /// Wait for the given number of spans to appear.
    /// </summary>
    /// <param name="count">The expected number of spans.</param>
    /// <param name="timeout">The timeout</param>
    /// <param name="operationName">The integration we're testing</param>
    /// <param name="minDateTime">Minimum time to check for spans from</param>
    /// <param name="returnAllOperations">When true, returns every span regardless of operation name</param>
    /// <returns>The list of spans.</returns>
    public IImmutableList <IMockSpan> WaitForSpans(
        int count,
        TimeSpan?timeout           = null,
        string operationName       = null,
        DateTimeOffset?minDateTime = null,
        bool returnAllOperations   = false)
    {
        timeout ??= DefaultSpanWaitTimeout;
        var deadline      = DateTime.Now.Add(timeout.Value);
        var minimumOffset = (minDateTime ?? DateTimeOffset.MinValue).ToUnixTimeNanoseconds();

        IImmutableList <IMockSpan> relevantSpans = ImmutableList <IMockSpan> .Empty;

        while (DateTime.Now < deadline)
        {
            relevantSpans =
                Spans
                .Where(s => SpanFilters.All(shouldReturn => shouldReturn(s)))
                .Where(s => s.Start > minimumOffset)
                .ToImmutableList();

            if (relevantSpans.Count(s => operationName == null || s.Name == operationName) >= count)
            {
                break;
            }

            Thread.Sleep(500);
        }

        if (!returnAllOperations)
        {
            relevantSpans =
                relevantSpans
                .Where(s => operationName == null || s.Name == operationName)
                .ToImmutableList();
        }

        return(relevantSpans);
    }