Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Jun 28, 2024
1 parent aa155ea commit 0932ed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion instrumentation/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,7 +37,7 @@ func TestRefreshGoCollector(t *testing.T) {
}

func allocateMemory(buffer [][]byte) [][]byte {
newBuffer := make([]byte, 100000)
newBuffer := make([]byte, 1000000)
for i := range newBuffer {
newBuffer[i] = 0
}
Expand Down
12 changes: 12 additions & 0 deletions instrumentation/runtime/test/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,3 +151,12 @@ func assertNonZeroValues(t *testing.T, sm metricdata.ScopeMetrics) {
}
}
}

func allocateMemory(buffer [][]byte) [][]byte {
newBuffer := make([]byte, 1000000)
for i := range newBuffer {
newBuffer[i] = 0
}
buffer = append(buffer, newBuffer)
return buffer
}

0 comments on commit 0932ed1

Please sign in to comment.