From ff069386e54234910dc43515ce9430b1be053277 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Sun, 23 Jun 2024 15:42:55 +0000 Subject: [PATCH] fix test --- instrumentation/runtime/runtime_test.go | 6 +++--- instrumentation/runtime/test/runtime_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/instrumentation/runtime/runtime_test.go b/instrumentation/runtime/runtime_test.go index b16a89f2600..135340aed65 100644 --- a/instrumentation/runtime/runtime_test.go +++ b/instrumentation/runtime/runtime_test.go @@ -19,6 +19,7 @@ func TestRefreshGoCollector(t *testing.T) { // before the first refresh, all counters are zero assert.Zero(t, collector.get(goMemoryAllocations)) // after the first refresh, counters are non-zero + allocateMemory(buffer) collector.refresh() initialAllocations := collector.get(goMemoryAllocations) assert.NotZero(t, initialAllocations) @@ -35,13 +36,12 @@ func TestRefreshGoCollector(t *testing.T) { assert.NotEqual(t, initialAllocations, collector.get(goMemoryAllocations)) } -func allocateMemory(buffer [][]byte) [][]byte { - newBuffer := make([]byte, 100000) +func allocateMemory(buffer [][]byte) { + newBuffer := make([]byte, 1000000) for i := range newBuffer { newBuffer[i] = 0 } buffer = append(buffer, newBuffer) - return buffer } func newClock() *clock { diff --git a/instrumentation/runtime/test/runtime_test.go b/instrumentation/runtime/test/runtime_test.go index 5c235331143..91dfc2b6ce1 100644 --- a/instrumentation/runtime/test/runtime_test.go +++ b/instrumentation/runtime/test/runtime_test.go @@ -22,6 +22,9 @@ import ( ) func TestRuntimeWithLimit(t *testing.T) { + // buffer for allocating memory + var buffer [][]byte + allocateMemory(buffer) t.Setenv("OTEL_GO_X_DEPRECATED_RUNTIME_METRICS", "false") debug.SetMemoryLimit(1234567890) // reset to default @@ -148,3 +151,11 @@ func assertNonZeroValues(t *testing.T, sm metricdata.ScopeMetrics) { } } } + +func allocateMemory(buffer [][]byte) { + newBuffer := make([]byte, 1000000) + for i := range newBuffer { + newBuffer[i] = 0 + } + buffer = append(buffer, newBuffer) +}