Skip to content

Commit

Permalink
update cgroup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam committed Feb 11, 2021
1 parent 097cb4c commit 5763e9e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/Elastic.Apm.Tests/Metrics/CgroupMetricsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void TestCgroup2Regex(string testString, string expected)
[Fact]
public void TestUnlimitedCgroup1()
{
var cgroupMetrics = CreateUnlimitedSystemCgroupMetricsProvider();
var cgroupMetrics = CreateUnlimitedSystemCgroupMetricsProvider("/proc/cgroup","/proc/unlimited/memory", "cgroup cgroup");
var samples = cgroupMetrics.GetSamples().ToList();

var memLimitSample = samples.SingleOrDefault(s => s.KeyValue.Key == SystemProcessCgroupMemoryMemLimitBytes);
Expand All @@ -98,7 +98,7 @@ public void TestUnlimitedCgroup1()
[Fact]
public void TestUnlimitedCgroup2()
{
var cgroupMetrics = CreateUnlimitedSystemCgroupMetricsProvider();
var cgroupMetrics = CreateUnlimitedSystemCgroupMetricsProvider("/proc/cgroup2","/proc/sys_cgroup2_unlimited", "cgroup2 cgroup");
var samples = cgroupMetrics.GetSamples().ToList();

var memLimitSample = samples.SingleOrDefault(s => s.KeyValue.Key == SystemProcessCgroupMemoryMemLimitBytes);
Expand All @@ -114,13 +114,13 @@ public void TestUnlimitedCgroup2()
/// </summary>
private string GetTestFilePath(string linuxPath) => Path.GetFullPath(Path.Combine(_projectRoot, "TestResources" + linuxPath));

private CgroupMetricsProvider CreateUnlimitedSystemCgroupMetricsProvider()
private CgroupMetricsProvider CreateUnlimitedSystemCgroupMetricsProvider(string cGroupPath, string mountPath, string cgroup)
{
var mountInfo = GetTestFilePath("/proc/unlimited/memory");
var mountInfo = GetTestFilePath(mountPath).Replace("\\", "/");
var tempFile = TempFile.CreateWithContents(
$"39 30 0:35 / {mountInfo} rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,seclabel,memory\n");
$"39 30 0:35 / {mountInfo} rw,nosuid,nodev,noexec,relatime shared:10 - {cgroup} rw,seclabel,memory\n");

return new CgroupMetricsProvider(GetTestFilePath("/proc/cgroup"), tempFile.Path, new NoopLogger());
return new CgroupMetricsProvider(GetTestFilePath(cGroupPath), tempFile.Path, new NoopLogger());
}
}
}

0 comments on commit 5763e9e

Please sign in to comment.