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 ff06938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 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 @@ -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 {
Expand Down
11 changes: 11 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,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)
}

0 comments on commit ff06938

Please sign in to comment.