Skip to content

Commit

Permalink
Modify order Harvest Host Tests to not collision cached files (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarocabanas committed Jun 17, 2024
1 parent c88f8d3 commit dc896c4
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions test/harvest/hostmetrics_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,6 @@ func TestHostSharedMemory(t *testing.T) {
})
}

func TestHostCachedMemory(t *testing.T) {
ctx := new(mocks.AgentContext)
ctx.On("Config").Return(&config.Config{
MetricsNetworkSampleRate: 1,
})
storageSampler := storage.NewSampler(ctx)

hostIDProvider := &hostid.ProviderMock{}
hostIDProvider.On("Provide").Return("some-host-id", nil)

systemSampler := metrics.NewSystemSampler(ctx, storageSampler, nil, hostIDProvider)

sampleB, _ := systemSampler.Sample()
beforeSample := sampleB[0].(*metrics.SystemSample)

f, err := ioutil.TempFile("/tmp", "")
assert.NoError(t, err)
defer os.Remove(f.Name())

// Force memory spike
for i := 0; i < 1e5; i++ {
f.Write([]byte("00000000000000000000"))
}

f.Sync()
f.Close()

_, err = ioutil.ReadFile(f.Name())

assert.NoError(t, err)

testhelpers.Eventually(t, timeout, func(st require.TestingT) {
sampleB, _ = systemSampler.Sample()
afterSample := sampleB[0].(*metrics.SystemSample)

expectedIncreaseBytes := 500000.0
assert.True(st, beforeSample.MemoryCachedBytes+expectedIncreaseBytes <= afterSample.MemoryCachedBytes, "CachedMemory used did not increase enough, expected an increase by %f CachedMemoryBefore: %f CachedMemoryAfter %f ", expectedIncreaseBytes, beforeSample.MemoryCachedBytes, afterSample.MemoryCachedBytes)
})
}

func TestHostDisk(t *testing.T) {
ctx := new(mocks.AgentContext)
ctx.On("Config").Return(&config.Config{
Expand Down Expand Up @@ -144,6 +104,46 @@ func TestHostDisk(t *testing.T) {
assert.True(t, *storageSample.UsedBytes+1e4 < sampleA.UsedBytes, "Used bytes did not increase enough, UserBytesBefore: %f UserBytesAfter %f ", *(storageSample.UsedBytes), sampleA.UsedBytes)
}

func TestHostCachedMemory(t *testing.T) {
ctx := new(mocks.AgentContext)
ctx.On("Config").Return(&config.Config{
MetricsNetworkSampleRate: 1,
})
storageSampler := storage.NewSampler(ctx)

hostIDProvider := &hostid.ProviderMock{}
hostIDProvider.On("Provide").Return("some-host-id", nil)

systemSampler := metrics.NewSystemSampler(ctx, storageSampler, nil, hostIDProvider)

sampleB, _ := systemSampler.Sample()
beforeSample := sampleB[0].(*metrics.SystemSample)

f, err := ioutil.TempFile("/tmp", "")
assert.NoError(t, err)
defer os.Remove(f.Name())

// Force memory spike
for i := 0; i < 1e5; i++ {
f.Write([]byte("00000000000000000000"))
}

f.Sync()
f.Close()

_, err = ioutil.ReadFile(f.Name())

assert.NoError(t, err)

testhelpers.Eventually(t, timeout, func(st require.TestingT) {
sampleB, _ = systemSampler.Sample()
afterSample := sampleB[0].(*metrics.SystemSample)

expectedIncreaseBytes := 500000.0
assert.True(st, beforeSample.MemoryCachedBytes+expectedIncreaseBytes <= afterSample.MemoryCachedBytes, "CachedMemory used did not increase enough, expected an increase by %f CachedMemoryBefore: %f CachedMemoryAfter %f ", expectedIncreaseBytes, beforeSample.MemoryCachedBytes, afterSample.MemoryCachedBytes)
})
}

func TestHostSlabMemory(t *testing.T) {
ctx := new(mocks.AgentContext)
ctx.On("Config").Return(&config.Config{
Expand Down

0 comments on commit dc896c4

Please sign in to comment.