Skip to content

Commit 78b5af2

Browse files
authored
Merge pull request #1576 from CosmWasm/1575_test
Fail fast on empty wasmvm cache metric setup
2 parents 7c6069d + 4595e6d commit 78b5af2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

x/wasm/keeper/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type WasmVMMetricsCollector struct {
2929

3030
// NewWasmVMMetricsCollector constructor
3131
func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector {
32+
if s == nil {
33+
panic("wasmvm instance must not be nil")
34+
}
3235
return &WasmVMMetricsCollector{
3336
source: s,
3437
CacheHitsDescr: prometheus.NewDesc("wasmvm_cache_hits_total", "Total number of cache hits", []string{"type"}, nil),

x/wasm/keeper/options_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package keeper
22

33
import (
4+
"github.com/prometheus/client_golang/prometheus"
45
"reflect"
56
"testing"
67

@@ -31,6 +32,15 @@ func TestConstructorOptions(t *testing.T) {
3132
assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM)
3233
},
3334
},
35+
"vm cache metrics": {
36+
srcOpt: WithVMCacheMetrics(prometheus.DefaultRegisterer),
37+
verify: func(t *testing.T, k Keeper) {
38+
t.Helper()
39+
registered := prometheus.DefaultRegisterer.Unregister(NewWasmVMMetricsCollector(k.wasmVM))
40+
assert.True(t, registered)
41+
},
42+
isPostOpt: true,
43+
},
3444
"decorate wasmvm": {
3545
srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine {
3646
require.IsType(t, &wasmvm.VM{}, old)

0 commit comments

Comments
 (0)