summaryrefslogtreecommitdiffhomepage
path: root/pkg/metric/metric_test.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-06-03 13:15:39 -0700
committergVisor bot <gvisor-bot@google.com>2021-06-03 13:18:43 -0700
commit758713f4c1b789495435a166167f231991828b46 (patch)
tree9a56f22710d72822cd109586fe871b2eb459d791 /pkg/metric/metric_test.go
parentddcd17399b1c1083a132772702d516c154815680 (diff)
Initialize metrics at init
Avoids a race condition at kernel initialization. Updates #6057. PiperOrigin-RevId: 377357723
Diffstat (limited to 'pkg/metric/metric_test.go')
-rw-r--r--pkg/metric/metric_test.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/pkg/metric/metric_test.go b/pkg/metric/metric_test.go
index c71dfd460..1b4a9e73a 100644
--- a/pkg/metric/metric_test.go
+++ b/pkg/metric/metric_test.go
@@ -48,6 +48,8 @@ func (s *sliceEmitter) Reset() {
var emitter sliceEmitter
func init() {
+ reset()
+
eventchannel.AddEmitter(&emitter)
}
@@ -77,7 +79,9 @@ func TestInitialize(t *testing.T) {
t.Fatalf("NewUint64Metric got err %v want nil", err)
}
- Initialize()
+ if err := Initialize(); err != nil {
+ t.Fatalf("Initialize(): %s", err)
+ }
if len(emitter) != 1 {
t.Fatalf("Initialize emitted %d events want 1", len(emitter))
@@ -149,7 +153,9 @@ func TestDisable(t *testing.T) {
t.Fatalf("NewUint64Metric got err %v want nil", err)
}
- Disable()
+ if err := Disable(); err != nil {
+ t.Fatalf("Disable(): %s", err)
+ }
if len(emitter) != 1 {
t.Fatalf("Initialize emitted %d events want 1", len(emitter))
@@ -178,7 +184,9 @@ func TestEmitMetricUpdate(t *testing.T) {
t.Fatalf("NewUint64Metric got err %v want nil", err)
}
- Initialize()
+ if err := Initialize(); err != nil {
+ t.Fatalf("Initialize(): %s", err)
+ }
// Don't care about the registration metrics.
emitter.Reset()
@@ -270,7 +278,9 @@ func TestEmitMetricUpdateWithFields(t *testing.T) {
t.Fatalf("NewUint64Metric got err %v want nil", err)
}
- Initialize()
+ if err := Initialize(); err != nil {
+ t.Fatalf("Initialize(): %s", err)
+ }
// Don't care about the registration metrics.
emitter.Reset()