(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func (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 | |
| 138 | func (s) TestServerMetrics_Merge(t *testing.T) { |
| 139 | sm1 := &ServerMetrics{ |
nothing calls this directly
no test coverage detected