コード例 #1
0
        public static void RunWithGlobalizationInvariantModeTest(bool predefinedCultures)
        {
            ProcessStartInfo psi = new ProcessStartInfo()
            {
                UseShellExecute = false
            };

            psi.Environment.Add("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
            psi.Environment.Add("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", predefinedCultures ? "1" : "0");
            RemoteExecutor.Invoke(() =>
            {
                // Ensure we are running inside the Globalization invariant mode.
                Assert.Equal("", CultureInfo.CurrentCulture.Name);

                // This test ensure creating PerformanceCounter object while we are running with Globalization Invariant Mode.
                // PerformanceCounter used to create cultures using LCID's which fail in Globalization Invariant Mode.
                // This test ensure no failure should be encountered in this case.
                using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter("Processor", "Interrupts/sec", "0", ".")))
                {
                    Assert.Equal("Processor", counterSample.CategoryName);
                }
            }, new RemoteInvokeOptions {
                StartInfo = psi
            }).Dispose();
        }
コード例 #2
0
        public static void PerformanceCounterCategory_ReadCategory()
        {
            PerformanceCounterCategory pcc = new PerformanceCounterCategory("Processor");

            InstanceDataCollectionCollection idColCol = Helpers.RetryOnAllPlatformsWithClosingResources(() => pcc.ReadCategory());

            Assert.NotNull(idColCol);
        }
コード例 #3
0
        public static void PerformanceCounter_CreateCounter_ProcessorCounter()
        {
            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter("Processor", "Interrupts/sec", "0", ".")))
            {
                Assert.Equal(0, Helpers.RetryOnAllPlatformsWithClosingResources(() => counterSample.NextValue()));

                Assert.True(counterSample.RawValue > 0);
            }
        }
コード例 #4
0
        public static void PerformanceCounter_BeginInit_ProcessorCounter()
        {
            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter("Processor", "Interrupts/sec", "0", ".")))
            {
                counterSample.BeginInit();

                Assert.NotNull(counterSample);
            }
        }
コード例 #5
0
        public static PerformanceCounter CreateCounterWithCategory(string categoryName, bool readOnly, PerformanceCounterCategoryType categoryType)
        {
            Helpers.CreateCategory(categoryName, categoryType);

            string counterName = categoryName.Replace("_Category", "_Counter");

            PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter(categoryName, counterName, readOnly));

            return(counterSample);
        }
コード例 #6
0
        public static InstanceDataCollectionCollection GetInstanceDataCollectionCollection()
        {
            PerformanceCounterCategory pcc = new PerformanceCounterCategory("Processor");

            return(Helpers.RetryOnAllPlatformsWithClosingResources(() =>
            {
                var idcc = pcc.ReadCategory();
                Assert.InRange(idcc.Values.Count, 1, int.MaxValue);
                return idcc;
            }));
        }
コード例 #7
0
        public static void PerformanceCounterCategory_CategoryType_SingleInstance()
        {
            string categoryName = nameof(PerformanceCounterCategory_CategoryType_SingleInstance) + "_Category";

            Helpers.CreateCategory(categoryName, PerformanceCounterCategoryType.SingleInstance);

            PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);

            Assert.Equal(PerformanceCounterCategoryType.SingleInstance, Helpers.RetryOnAllPlatformsWithClosingResources(() => pcc.CategoryType));
            PerformanceCounterCategory.Delete(categoryName);
        }
コード例 #8
0
        public static void PerformanceCounterCategory_InstanceExists_Static()
        {
            PerformanceCounterCategory pcc = new PerformanceCounterCategory("Processor");

            string[] instances = Helpers.RetryOnAllPlatformsWithClosingResources(() => pcc.GetInstanceNames());
            Assert.True(instances.Length > 0);

            foreach (string instance in instances)
            {
                Assert.True(PerformanceCounterCategory.InstanceExists(instance, "Processor"));
            }
        }
コード例 #9
0
        public static void PerformanceCounter_CreateCounter_SetReadOnly()
        {
            string categoryName = nameof(PerformanceCounter_CreateCounter_SetReadOnly) + "_Category";
            string counterName  = nameof(PerformanceCounter_CreateCounter_SetReadOnly) + "_Counter";

            Helpers.CreateCategory(categoryName, PerformanceCounterCategoryType.SingleInstance);

            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter(categoryName, counterName)))
            {
                counterSample.ReadOnly = false;

                Assert.False(counterSample.ReadOnly);
            }

            Helpers.DeleteCategory(categoryName);
        }
コード例 #10
0
        public static void PerformanceCounter_NextSample_MultiInstance()
        {
            string categoryName = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Category";
            string counterName  = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Counter";
            string instanceName = nameof(PerformanceCounter_NextSample_MultiInstance) + "_Instance";

            Helpers.CreateCategory(categoryName, PerformanceCounterCategoryType.MultiInstance);

            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter(categoryName, counterName, instanceName, readOnly: false)))
            {
                counterSample.RawValue = 10;
                Helpers.RetryOnAllPlatformsWithClosingResources(() => counterSample.Decrement());

                Assert.Equal(9, counterSample.RawValue);
            }

            Helpers.DeleteCategory(categoryName);
        }
コード例 #11
0
        public static void PerformanceCounter_CreateCounter_MultiInstanceReadOnly()
        {
            string categoryName = nameof(PerformanceCounter_CreateCounter_MultiInstanceReadOnly) + "_Category";
            string counterName  = nameof(PerformanceCounter_CreateCounter_MultiInstanceReadOnly) + "_Counter";
            string instanceName = nameof(PerformanceCounter_CreateCounter_MultiInstanceReadOnly) + "_Instance";

            Helpers.CreateCategory(categoryName, counterName, PerformanceCounterCategoryType.MultiInstance);

            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter(categoryName, counterName, instanceName)))
            {
                Assert.Equal(counterName, counterSample.CounterName);
                Assert.Equal(categoryName, counterSample.CategoryName);
                Assert.Equal(instanceName, counterSample.InstanceName);
                Assert.Equal("counter description", Helpers.RetryOnAllPlatformsWithClosingResources(() => counterSample.CounterHelp));
                Assert.True(counterSample.ReadOnly);
            }

            Helpers.DeleteCategory(categoryName);
        }
コード例 #12
0
        public static void PerformanceCounter_NextValue_ProcessorCounter()
        {
            using (PerformanceCounter counterSample = Helpers.RetryOnAllPlatformsWithClosingResources(() => new PerformanceCounter("Processor", "Interrupts/sec", "_Total", ".")))
            {
                float val;
                int   counter = 0;
                do
                {
                    // Ensure we don't always return zero for a counter we know is not always zero
                    val = Helpers.RetryOnAllPlatformsWithClosingResources(() => counterSample.NextValue());
                    if (val > 0f)
                    {
                        break;
                    }
                    counter++;
                    Thread.Sleep(100);
                }while (counter < 20);

                Assert.True(val > 0f);
            }
        }