Esempio n. 1
0
        public static void FinalCleanup()
        {
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEnabled, null);
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetrySchedulingInSeconds, null);
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEndpoint, null);

            ClientTelemetryTests.ResetSystemUsageMonitor(false);
        }
Esempio n. 2
0
        public static void ClassInitialize(TestContext context)
        {
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEnabled, "true");
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetrySchedulingInSeconds, "1");
            Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEndpoint, telemetryEndpointUrl);

            SystemUsageMonitor oldSystemUsageMonitor = (SystemUsageMonitor)typeof(DiagnosticsHandlerHelper)
                                                       .GetField("systemUsageMonitor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(DiagnosticsHandlerHelper.Instance);

            oldSystemUsageMonitor.Stop();

            ClientTelemetryTests.ResetSystemUsageMonitor(true);
        }
Esempio n. 3
0
        /// <summary>
        /// This method wait for the expected operations to get recorded by telemetry and assert the values
        /// </summary>
        /// <param name="expectedOperationCount"> Expected number of unique OperationInfo irrespective of response size.  </param>
        /// <param name="expectedConsistencyLevel"> Expected Consistency level of the operation recorded by telemetry</param>
        /// <param name="expectedOperationRecordCountMap"> Expected number of requests recorded for each operation </param>
        /// <returns></returns>
        private async Task WaitAndAssert(
            int expectedOperationCount = 0,
            Microsoft.Azure.Cosmos.ConsistencyLevel?expectedConsistencyLevel = null,
            IDictionary <string, long> expectedOperationRecordCountMap       = null,
            string expectedSubstatuscode = null)
        {
            Assert.IsNotNull(this.actualInfo, "Telemetry Information not available");

            // As this feature is thread based execution so wait for the results to avoid test flakiness
            List <ClientTelemetryProperties> localCopyOfActualInfo = null;
            Stopwatch stopwatch = Stopwatch.StartNew();

            do
            {
                await Task.Delay(TimeSpan.FromMilliseconds(1500)); // wait at least for 1 round of telemetry

                await Task.Delay(TimeSpan.FromMilliseconds(1500));

                HashSet <OperationInfo> actualOperationSet = new HashSet <OperationInfo>();
                lock (this.actualInfo)
                {
                    // Setting the number of unique OperationInfo irrespective of response size as response size is varying in case of queries.
                    this.actualInfo
                    .ForEach(x => x.OperationInfo
                             .ForEach(y =>
                    {
                        y.GreaterThan1Kb = false;
                        actualOperationSet.Add(y);
                    }));

                    if (actualOperationSet.Count == expectedOperationCount / 2)
                    {
                        // Copy the list to avoid it being modified while validating
                        localCopyOfActualInfo = new List <ClientTelemetryProperties>(this.actualInfo);
                        break;
                    }

                    Assert.IsTrue(stopwatch.Elapsed.TotalMinutes < 1, $"The expected operation count({expectedOperationCount}) was never hit, Actual Operation Count is {actualOperationSet.Count}.  ActualInfo:{JsonConvert.SerializeObject(this.actualInfo)}");
                }
            }while (localCopyOfActualInfo == null);

            List <OperationInfo> actualOperationList     = new List <OperationInfo>();
            List <SystemInfo>    actualSystemInformation = new List <SystemInfo>();

            ClientTelemetryTests.AssertAccountLevelInformation(localCopyOfActualInfo, actualOperationList, actualSystemInformation);
            ClientTelemetryTests.AssertOperationLevelInformation(expectedConsistencyLevel, expectedOperationRecordCountMap, actualOperationList, expectedSubstatuscode);
            ClientTelemetryTests.AssertSystemLevelInformation(actualSystemInformation);
        }