MCPcopy
hub / github.com/grpc/grpc-go / TestServerMetrics_Setters_Range

Method TestServerMetrics_Setters_Range

orca/server_metrics_test.go:99–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func (s) TestServerMetrics_Setters_Range(t *testing.T) {
100 smr := NewServerMetricsRecorder()
101
102 smr.SetCPUUtilization(0.1)
103 smr.SetMemoryUtilization(0.2)
104 smr.SetApplicationUtilization(0.3)
105 smr.SetQPS(0.4)
106 smr.SetEPS(0.5)
107 smr.SetNamedUtilization("x", 0.6)
108
109 // Negatives for all these fields should be ignored.
110 smr.SetCPUUtilization(-2)
111 smr.SetMemoryUtilization(-3)
112 smr.SetApplicationUtilization(-4)
113 smr.SetQPS(-0.1)
114 smr.SetEPS(-0.6)
115 smr.SetNamedUtilization("x", -2)
116
117 // Memory and named utilizations over 1 are ignored.
118 smr.SetMemoryUtilization(1.1)
119 smr.SetNamedUtilization("x", 1.1)
120
121 want := &ServerMetrics{
122 CPUUtilization: 0.1,
123 MemUtilization: 0.2,
124 AppUtilization: 0.3,
125 QPS: 0.4,
126 EPS: 0.5,
127 Utilization: map[string]float64{"x": 0.6},
128 NamedMetrics: map[string]float64{},
129 RequestCost: map[string]float64{},
130 }
131
132 got := smr.ServerMetrics()
133 if d := cmp.Diff(got, want); d != "" {
134 t.Fatalf("unexpected server metrics: -got +want: %v", d)
135 }
136}
137
138func (s) TestServerMetrics_Merge(t *testing.T) {
139 sm1 := &ServerMetrics{

Callers

nothing calls this directly

Calls 9

SetCPUUtilizationMethod · 0.95
SetMemoryUtilizationMethod · 0.95
SetQPSMethod · 0.95
SetEPSMethod · 0.95
SetNamedUtilizationMethod · 0.95
NewServerMetricsRecorderFunction · 0.85
ServerMetricsMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected