github.com/blend/go-sdk@v1.20220411.3/stats/runtime_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package stats 9 10 import ( 11 "fmt" 12 "runtime" 13 "testing" 14 15 "github.com/blend/go-sdk/assert" 16 ) 17 18 var runtimeMetrics = []string{ 19 "go.runtime.mem.num_gc", 20 "go.runtime.mem.num_forced_gc", 21 "go.runtime.mem.pause_total_ns", 22 "go.runtime.mem.frees", 23 "go.runtime.mem.mallocs", 24 "go.runtime.num_cpu", 25 "go.runtime.num_goroutine", 26 "go.runtime.mem.alloc", 27 "go.runtime.mem.gc_sys", 28 "go.runtime.mem.other_sys", 29 "go.runtime.mem.heap_alloc", 30 "go.runtime.mem.heap_idle", 31 "go.runtime.mem.heap_inuse", 32 "go.runtime.mem.heap_objects", 33 "go.runtime.mem.heap_sys", 34 "go.runtime.mem.stack_inuse", 35 "go.runtime.mem.stack_sys", 36 "go.runtime.mem.sys", 37 "go.runtime.mem.total_alloc", 38 } 39 40 func TestRuntimeCollect(t *testing.T) { 41 assert := assert.New(t) 42 43 var previous, current runtime.MemStats 44 runtime.ReadMemStats(&previous) 45 46 collector := NewMockCollector(32) 47 for i := 0; i < len(runtimeMetrics); i++ { 48 go func() { collector.Errors <- fmt.Errorf("error") }() 49 } 50 go runtimeCollect(collector, &previous, ¤t) 51 52 for _, metricName := range runtimeMetrics { 53 metric := <-collector.Metrics 54 assert.Equal(metricName, metric.Name) 55 assert.Zero(metric.Count) 56 assert.Zero(metric.Histogram) 57 assert.Zero(metric.TimeInMilliseconds) 58 } 59 }