async Task <DirectMethodReportGeneratorMetadata> ProcessSenderAndReceiverResults(
            DirectMethodTestResult dmSenderTestResult,
            bool hasSenderResult,
            bool hasReceiverResult,
            NetworkControllerStatus networkControllerStatus,
            bool isWithinTolerancePeriod)
        {
            ulong  mismatchSuccess = 0;
            string receiverSource  = this.ReceiverSource.OrDefault();
            ITestResultCollection <TestOperationResult> receiverTestResults = this.ReceiverTestResults.OrDefault();

            this.ValidateDataSource(receiverTestResults.Current, receiverSource);
            DirectMethodTestResult dmReceiverTestResult = JsonConvert.DeserializeObject <DirectMethodTestResult>(receiverTestResults.Current.Result);

            if (!string.Equals(dmSenderTestResult.TrackingId, dmReceiverTestResult.TrackingId, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidDataException($"Sequence numbers should not match if the testResults didn't match. SenderTestResult: " +
                                               $"{dmSenderTestResult.GetFormattedResult()}. ReceiverTestResult: {dmReceiverTestResult.GetFormattedResult()}");
            }

            if (string.Equals(dmSenderTestResult.SequenceNumber, dmReceiverTestResult.SequenceNumber, StringComparison.OrdinalIgnoreCase))
            {
                hasReceiverResult = await receiverTestResults.MoveNextAsync();
            }
            else
            {
                if (int.Parse(dmSenderTestResult.SequenceNumber) > int.Parse(dmReceiverTestResult.SequenceNumber))
                {
                    return(await this.ProcessMismatchFailureCase());
                }
                else if (int.Parse(dmSenderTestResult.SequenceNumber) < int.Parse(dmReceiverTestResult.SequenceNumber))
                {
                    if (HttpStatusCode.OK.Equals(dmSenderTestResult.HttpStatusCode) &&
                        (NetworkControllerStatus.Disabled.Equals(networkControllerStatus) ||
                         (NetworkControllerStatus.Enabled.Equals(networkControllerStatus) && isWithinTolerancePeriod)))
                    {
                        mismatchSuccess++;
                        hasSenderResult = await this.SenderTestResults.MoveNextAsync();

                        return(new DirectMethodReportGeneratorMetadata {
                            MismatchSuccess = mismatchSuccess, HasReceiverResult = hasReceiverResult, HasSenderResult = hasSenderResult
                        });
                    }
                }
            }

            return(new DirectMethodReportGeneratorMetadata {
                HasSenderResult = hasSenderResult, HasReceiverResult = hasReceiverResult
            });
        }
Esempio n. 2
0
        public static async Task <NetworkStatusTimeline> CreateAsync(
            ITestResultCollection <TestOperationResult> networkControllerTestOperationResults,
            TimeSpan tolerancePeriod,
            NetworkControllerStatus initialNetworkControllerStatus = NetworkControllerStatus.Disabled)
        {
            List <NetworkControllerTestResult> networkControllerTestResults = new List <NetworkControllerTestResult>();

            while (await networkControllerTestOperationResults.MoveNextAsync())
            {
                Option <NetworkControllerTestResult> networkControllerTestResult = GetNetworkControllerTestOperationResult(networkControllerTestOperationResults.Current);

                networkControllerTestResult.ForEach(
                    r =>
                {
                    networkControllerTestResults.Add(r);
                });
            }

            return(new NetworkStatusTimeline(networkControllerTestResults, tolerancePeriod, initialNetworkControllerStatus));
        }
        async Task <DirectMethodReportGeneratorMetadata> ProcessMismatchFailureCase()
        {
            ulong mismatchFailure = 0;
            ITestResultCollection <TestOperationResult> receiverTestResults = this.ReceiverTestResults.OrDefault();

            Logger.LogError($"[{nameof(DirectMethodReportGenerator)}] Receiver test result source has unexpected results.");

            mismatchFailure++;

            // Log actual queue items
            Logger.LogError($"Unexpected Receiver test result: {receiverTestResults.Current.Source}, " +
                            $"{receiverTestResults.Current.Type}, " +
                            $"{receiverTestResults.Current.Result} at " +
                            $"{receiverTestResults.Current.CreatedAt}");
            bool hasReceiverResult = await receiverTestResults.MoveNextAsync();

            return(new DirectMethodReportGeneratorMetadata {
                MismatchFailure = mismatchFailure, HasReceiverResult = hasReceiverResult
            });
        }
        async Task <DirectMethodReportGeneratorMetadata> ProcessSenderTestResults(
            DirectMethodTestResult dmSenderTestResult,
            NetworkControllerStatus networkControllerStatus,
            bool isWithinTolerancePeriod,
            ITestResultCollection <TestOperationResult> senderTestResults)
        {
            ulong          networkOnSuccess           = 0;
            ulong          networkOffSuccess          = 0;
            ulong          networkOnToleratedSuccess  = 0;
            ulong          networkOffToleratedSuccess = 0;
            ulong          networkOnFailure           = 0;
            ulong          networkOffFailure          = 0;
            HttpStatusCode statusCode = dmSenderTestResult.HttpStatusCode;

            if (NetworkControllerStatus.Disabled.Equals(networkControllerStatus))
            {
                if (HttpStatusCode.OK.Equals(statusCode))
                {
                    networkOnSuccess++;
                }
                else
                {
                    if (isWithinTolerancePeriod)
                    {
                        networkOnToleratedSuccess++;
                    }
                    else
                    {
                        networkOnFailure++;
                    }
                }
            }
            else if (NetworkControllerStatus.Enabled.Equals(networkControllerStatus))
            {
                if (HttpStatusCode.InternalServerError.Equals(statusCode))
                {
                    networkOffSuccess++;
                }
                else if (HttpStatusCode.OK.Equals(dmSenderTestResult.HttpStatusCode))
                {
                    if (isWithinTolerancePeriod)
                    {
                        networkOffToleratedSuccess++;
                    }
                    else
                    {
                        networkOffFailure++;
                    }
                }
                else
                {
                    throw new InvalidDataException($"Unexpected HttpStatusCode of {statusCode}");
                }
            }

            bool hasSenderResult = await senderTestResults.MoveNextAsync();

            return(new DirectMethodReportGeneratorMetadata
            {
                NetworkOnSuccess = networkOnSuccess,
                NetworkOffSuccess = networkOffSuccess,
                NetworkOnToleratedSuccess = networkOnToleratedSuccess,
                NetworkOffToleratedSuccess = networkOffToleratedSuccess,
                NetworkOnFailure = networkOnFailure,
                NetworkOffFailure = networkOffFailure,
                HasSenderResult = hasSenderResult
            });
        }