Repository: grpc/grpc-go
File: experimental/stats/metricregistry_test.go (Go)

Code before:
		t.Fatalf("fmr.intValues[intUpDownCountHandle1.MetricDescriptor] got %v, want: %v", got, 2)
	}

	floatCountHandle1.Record(fmr, 1.2, []string{"some label value", "some optional label value"}...)
	if got := fmr.floatValues[floatCountHandle1.Descriptor()]; got != 1.2 {
		t.Fatalf("fmr.floatValues[floatCountHandle1.MetricDescriptor] got %v, want: %v", got, 1.2)
	}

	intHistoHandle1.Record(fmr, 3, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intHistoHandle1.Descriptor()]; got != 3 {
		t.Fatalf("fmr.intValues[intHistoHandle1.MetricDescriptor] got %v, want: %v", got, 3)
	}

	floatHistoHandle1.Record(fmr, 4.3, []string{"some label value", "some optional label value"}...)
	if got := fmr.floatValues[floatHistoHandle1.Descriptor()]; got != 4.3 {
		t.Fatalf("fmr.floatValues[floatHistoHandle1.MetricDescriptor] got %v, want: %v", got, 4.3)
	}

	intGaugeHandle1.Record(fmr, 7, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intGaugeHandle1.Descriptor()]; got != 7 {
		t.Fatalf("fmr.intValues[intGaugeHandle1.MetricDescriptor] got %v, want: %v", got, 7)
	}
	intAsyncGaugeHandle1.Record(fmr, 7, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intGaugeHandle1.Descriptor()]; got != 7 {
		t.Fatalf("fmr.intValues[intGaugeHandle1.MetricDescriptor] got %v, want: %v", got, 7)
	}
}

func (s) TestUpDownCounts(t *testing.T) {
	cleanup := snapshotMetricsRegistryForTesting()
	defer cleanup()

	intUpDownCountHandle1 := RegisterInt64UpDownCount(MetricDescriptor{
		Name:           "simple up down counter",
		Description:    "current number of emissions from tests",
		Unit:           "int",
		Labels:         []string{"int up down counter label"},
		OptionalLabels: []string{"int up down counter optional label"},
		Default:        false,
	})

	fmr := newFakeMetricsRecorder(t)
	intUpDownCountHandle1.Record(fmr, 2, []string{"up down value", "some optional label value"}...)
	intUpDownCountHandle1.Record(fmr, -1, []string{"up down value", "some optional label value"}...)

	if got := fmr.intValues[intUpDownCountHandle1.Descriptor()]; got != 1 {
		t.Fatalf("fmr.intValues[intUpDownCountHandle1.MetricDescriptor] got %v, want: %v", got, 1)
	}
}

// TestNumerousIntCounts tests numerous int count metrics registered onto the

Review comment (suggestion):
The test should use `intAsyncGaugeHandle1` here, seems like a copy/paste error.

Code after:
		t.Fatalf("fmr.intValues[intUpDownCountHandle1.MetricDescriptor] got %v, want: %v", got, 2)
	}

	floatCountHandle1.Record(fmr, 1.2, []string{"some label value", "some optional label value"}...)
	if got := fmr.floatValues[floatCountHandle1.Descriptor()]; got != 1.2 {
		t.Fatalf("fmr.floatValues[floatCountHandle1.MetricDescriptor] got %v, want: %v", got, 1.2)
	}

	intHistoHandle1.Record(fmr, 3, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intHistoHandle1.Descriptor()]; got != 3 {
		t.Fatalf("fmr.intValues[intHistoHandle1.MetricDescriptor] got %v, want: %v", got, 3)
	}

	floatHistoHandle1.Record(fmr, 4.3, []string{"some label value", "some optional label value"}...)
	if got := fmr.floatValues[floatHistoHandle1.Descriptor()]; got != 4.3 {
		t.Fatalf("fmr.floatValues[floatHistoHandle1.MetricDescriptor] got %v, want: %v", got, 4.3)
	}

	intGaugeHandle1.Record(fmr, 7, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intGaugeHandle1.Descriptor()]; got != 7 {
		t.Fatalf("fmr.intValues[intGaugeHandle1.MetricDescriptor] got %v, want: %v", got, 7)
	}
	intAsyncGaugeHandle1.Record(fmr, 9, []string{"some label value", "some optional label value"}...)
	if got := fmr.intValues[intAsyncGaugeHandle1.Descriptor()]; got != 9 {
		t.Fatalf("fmr.intValues[intAsyncGaugeHandle1.MetricDescriptor] got %v, want: %v", got, 9)
	}
}

func (s) TestUpDownCounts(t *testing.T) {
	cleanup := snapshotMetricsRegistryForTesting()
	defer cleanup()

	intUpDownCountHandle1 := RegisterInt64UpDownCount(MetricDescriptor{
		Name:           "simple up down counter",
		Description:    "current number of emissions from tests",
		Unit:           "int",
		Labels:         []string{"int up down counter label"},
		OptionalLabels: []string{"int up down counter optional label"},
		Default:        false,
	})

	fmr := newFakeMetricsRecorder(t)
	intUpDownCountHandle1.Record(fmr, 2, []string{"up down value", "some optional label value"}...)
	intUpDownCountHandle1.Record(fmr, -1, []string{"up down value", "some optional label value"}...)

	if got := fmr.intValues[intUpDownCountHandle1.Descriptor()]; got != 1 {
		t.Fatalf("fmr.intValues[intUpDownCountHandle1.MetricDescriptor] got %v, want: %v", got, 1)
	}
}

// TestNumerousIntCounts tests numerous int count metrics registered onto the