Blame corefx-39686-cgroupv2-02.patch

b18622e
From 9a8c5e4014ffca8aff70808cc0e50a403d38c292 Mon Sep 17 00:00:00 2001
b18622e
From: Stephen Toub <stoub@microsoft.com>
b18622e
Date: Wed, 23 Oct 2019 20:35:49 -0400
b18622e
Subject: [PATCH 2/2] Clean up new tests
b18622e
b18622e
---
b18622e
 .../tests/Tests/Interop/cgroupsTests.cs       | 79 ++++++-------------
b18622e
 1 file changed, 25 insertions(+), 54 deletions(-)
b18622e
b18622e
diff --git a/src/Common/tests/Tests/Interop/cgroupsTests.cs b/src/Common/tests/Tests/Interop/cgroupsTests.cs
b18622e
index f16d9242879c..fc6ab5c9753c 100644
b18622e
--- a/src/Common/tests/Tests/Interop/cgroupsTests.cs
b18622e
+++ b/src/Common/tests/Tests/Interop/cgroupsTests.cs
b18622e
@@ -2,38 +2,27 @@
b18622e
 // The .NET Foundation licenses this file to you under the MIT license.
b18622e
 // See the LICENSE file in the project root for more information.
b18622e
 
b18622e
-using System;
b18622e
 using System.IO;
b18622e
-using System.Text;
b18622e
 using Xunit;
b18622e
 
b18622e
 namespace Common.Tests
b18622e
 {
b18622e
-    public class cgroupsTests
b18622e
+    public class cgroupsTests : FileCleanupTestBase
b18622e
     {
b18622e
         [Theory]
b18622e
-        [InlineData(true, "0",  0)]
b18622e
-        [InlineData(false, "max",  0)]
b18622e
-        [InlineData(true, "1k",  1024)]
b18622e
-        [InlineData(true, "1K",  1024)]
b18622e
-        public static void ValidateTryReadMemoryValue(bool expectedResult, string valueText, ulong expectedValue)
b18622e
+        [InlineData(true, "0", 0)]
b18622e
+        [InlineData(false, "max", 0)]
b18622e
+        [InlineData(true, "1k", 1024)]
b18622e
+        [InlineData(true, "1K", 1024)]
b18622e
+        public void ValidateTryReadMemoryValue(bool expectedResult, string valueText, ulong expectedValue)
b18622e
         {
b18622e
-            string path = Path.GetTempFileName();
b18622e
-            try
b18622e
-            {
b18622e
-                File.WriteAllText(path, valueText);
b18622e
-
b18622e
-                bool result = Interop.cgroups.TryReadMemoryValueFromFile(path, out ulong val);
b18622e
+            string path = GetTestFilePath();
b18622e
+            File.WriteAllText(path, valueText);
b18622e
 
b18622e
-                Assert.Equal(expectedResult, result);
b18622e
-                if (result)
b18622e
-                {
b18622e
-                    Assert.Equal(expectedValue, val);
b18622e
-                }
b18622e
-            }
b18622e
-            finally
b18622e
+            Assert.Equal(expectedResult, Interop.cgroups.TryReadMemoryValueFromFile(path, out ulong val));
b18622e
+            if (expectedResult)
b18622e
             {
b18622e
-                File.Delete(path);
b18622e
+                Assert.Equal(expectedValue, val);
b18622e
             }
b18622e
         }
b18622e
 
b18622e
@@ -50,26 +39,17 @@ public static void ValidateTryReadMemoryValue(bool expectedResult, string valueT
b18622e
         [InlineData(true, "0 0 0:0 / /foo ignore ignore - cgroup cgroup cpu,memory", "memory", 1, "/", "/foo")]
b18622e
         [InlineData(true, "0 0 0:0 / /foo ignore ignore - cgroup cgroup memory,cpu", "memory", 1, "/", "/foo")]
b18622e
         [InlineData(false, "0 0 0:0 / /foo ignore ignore - cgroup cgroup cpu", "memory", 0, "/", "/foo")]
b18622e
-        public static void ParseValidateMountInfo(bool found, string procSelfMountInfoText, string subsystem, int expectedVersion, string expectedRoot, string expectedMount)
b18622e
+        public void ParseValidateMountInfo(bool expectedFound, string procSelfMountInfoText, string subsystem, int expectedVersion, string expectedRoot, string expectedMount)
b18622e
         {
b18622e
-            string path = Path.GetTempFileName();
b18622e
-            try
b18622e
-            {
b18622e
-                File.WriteAllText(path, procSelfMountInfoText);
b18622e
-
b18622e
-                bool result = Interop.cgroups.TryFindHierarchyMount(path, subsystem,  out Interop.cgroups.CGroupVersion version, out string root, out string mount);
b18622e
+            string path = GetTestFilePath();
b18622e
+            File.WriteAllText(path, procSelfMountInfoText);
b18622e
 
b18622e
-                Assert.Equal(found, result);
b18622e
-                if (found)
b18622e
-                {
b18622e
-                    Assert.Equal(expectedVersion, (int)version);
b18622e
-                    Assert.Equal(expectedRoot, root);
b18622e
-                    Assert.Equal(expectedMount, mount);
b18622e
-                }
b18622e
-            }
b18622e
-            finally
b18622e
+            Assert.Equal(expectedFound, Interop.cgroups.TryFindHierarchyMount(path, subsystem, out Interop.cgroups.CGroupVersion version, out string root, out string mount));
b18622e
+            if (expectedFound)
b18622e
             {
b18622e
-                File.Delete(path);
b18622e
+                Assert.Equal(expectedVersion, (int)version);
b18622e
+                Assert.Equal(expectedRoot, root);
b18622e
+                Assert.Equal(expectedMount, mount);
b18622e
             }
b18622e
         }
b18622e
 
b18622e
@@ -83,24 +63,15 @@ public static void ParseValidateMountInfo(bool found, string procSelfMountInfoTe
b18622e
         [InlineData(false, "2:foo:bar", "bar", "ignore")]
b18622e
         [InlineData(true, "1:foo:bar\n2:eggs:spam", "foo", "bar")]
b18622e
         [InlineData(true, "1:foo:bar\n2:eggs:spam", "eggs", "spam")]
b18622e
-        public static void ParseValidateProcCGroup(bool found, string procSelfCgroupText, string subsystem, string expectedMountPath)
b18622e
+        public void ParseValidateProcCGroup(bool expectedFound, string procSelfCgroupText, string subsystem, string expectedMountPath)
b18622e
         {
b18622e
-            string path = Path.GetTempFileName();
b18622e
-            try
b18622e
-            {
b18622e
-                File.WriteAllText(path, procSelfCgroupText);
b18622e
+            string path = GetTestFilePath();
b18622e
+            File.WriteAllText(path, procSelfCgroupText);
b18622e
 
b18622e
-                bool result = Interop.cgroups.TryFindCGroupPathForSubsystem(path, subsystem,  out string mountPath);
b18622e
-
b18622e
-                Assert.Equal(found, result);
b18622e
-                if (found)
b18622e
-                {
b18622e
-                    Assert.Equal(expectedMountPath, mountPath);
b18622e
-                }
b18622e
-            }
b18622e
-            finally
b18622e
+            Assert.Equal(expectedFound, Interop.cgroups.TryFindCGroupPathForSubsystem(path, subsystem, out string mountPath));
b18622e
+            if (expectedFound)
b18622e
             {
b18622e
-                File.Delete(path);
b18622e
+                Assert.Equal(expectedMountPath, mountPath);
b18622e
             }
b18622e
         }
b18622e
     }