Skip to content

Commit

Permalink
add back pruner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Nov 12, 2024
1 parent 8eff09c commit df4dc18
Showing 1 changed file with 42 additions and 43 deletions.
85 changes: 42 additions & 43 deletions api/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,48 @@ func TestMetricsMiddleware(t *testing.T) {
router.Use(metricsMiddleware)
ts := httptest.NewServer(router)

// httpGet(t, ts.URL+"/accounts/0x")
// httpGet(t, ts.URL+"/accounts/"+thor.Address{}.String())

// _, code := httpGet(t, ts.URL+"/accounts/"+thor.Address{}.String()+"?revision="+blkID.String())
// assert.Equal(t, 500, code)

// body, _ := httpGet(t, ts.URL+"/metrics")
// parser := expfmt.TextParser{}
// metrics, err := parser.TextToMetricFamilies(bytes.NewReader(body))
// assert.Nil(t, err)

// m := metrics["thor_metrics_api_request_count"].GetMetric()
// assert.Equal(t, 3, len(m), "should be 3 metric entries")
// assert.Equal(t, float64(1), m[0].GetCounter().GetValue())
// assert.Equal(t, float64(1), m[1].GetCounter().GetValue())

// labels := m[0].GetLabel()
// assert.Equal(t, 3, len(labels))
// assert.Equal(t, "code", labels[0].GetName())
// assert.Equal(t, "200", labels[0].GetValue())
// assert.Equal(t, "method", labels[1].GetName())
// assert.Equal(t, "GET", labels[1].GetValue())
// assert.Equal(t, "name", labels[2].GetName())
// assert.Equal(t, "accounts_get_account", labels[2].GetValue())

// labels = m[1].GetLabel()
// assert.Equal(t, 3, len(labels))
// assert.Equal(t, "code", labels[0].GetName())
// assert.Equal(t, "400", labels[0].GetValue())
// assert.Equal(t, "method", labels[1].GetName())
// assert.Equal(t, "GET", labels[1].GetValue())
// assert.Equal(t, "name", labels[2].GetName())
// assert.Equal(t, "accounts_get_account", labels[2].GetValue())

// labels = m[2].GetLabel()
// assert.Equal(t, 3, len(labels))
// assert.Equal(t, "code", labels[0].GetName())
// assert.Equal(t, "500", labels[0].GetValue())
// assert.Equal(t, "method", labels[1].GetName())
// assert.Equal(t, "GET", labels[1].GetValue())
// assert.Equal(t, "name", labels[2].GetName())
// assert.Equal(t, "accounts_get_account", labels[2].GetValue())
// }
httpGet(t, ts.URL+"/accounts/0x")
httpGet(t, ts.URL+"/accounts/"+thor.Address{}.String())

_, code := httpGet(t, ts.URL+"/accounts/"+thor.Address{}.String()+"?revision="+blkID.String())
assert.Equal(t, 500, code)

body, _ := httpGet(t, ts.URL+"/metrics")
parser := expfmt.TextParser{}
metrics, err := parser.TextToMetricFamilies(bytes.NewReader(body))
assert.Nil(t, err)

m := metrics["thor_metrics_api_request_count"].GetMetric()
assert.Equal(t, 3, len(m), "should be 3 metric entries")
assert.Equal(t, float64(1), m[0].GetCounter().GetValue())
assert.Equal(t, float64(1), m[1].GetCounter().GetValue())

labels := m[0].GetLabel()
assert.Equal(t, 3, len(labels))
assert.Equal(t, "code", labels[0].GetName())
assert.Equal(t, "200", labels[0].GetValue())
assert.Equal(t, "method", labels[1].GetName())
assert.Equal(t, "GET", labels[1].GetValue())
assert.Equal(t, "name", labels[2].GetName())
assert.Equal(t, "accounts_get_account", labels[2].GetValue())

labels = m[1].GetLabel()
assert.Equal(t, 3, len(labels))
assert.Equal(t, "code", labels[0].GetName())
assert.Equal(t, "400", labels[0].GetValue())
assert.Equal(t, "method", labels[1].GetName())
assert.Equal(t, "GET", labels[1].GetValue())
assert.Equal(t, "name", labels[2].GetName())
assert.Equal(t, "accounts_get_account", labels[2].GetValue())

labels = m[2].GetLabel()
assert.Equal(t, 3, len(labels))
assert.Equal(t, "code", labels[0].GetName())
assert.Equal(t, "500", labels[0].GetValue())
assert.Equal(t, "method", labels[1].GetName())
assert.Equal(t, "GET", labels[1].GetValue())
assert.Equal(t, "name", labels[2].GetName())
assert.Equal(t, "accounts_get_account", labels[2].GetValue())
}

func TestWebsocketMetrics(t *testing.T) {
Expand Down

0 comments on commit df4dc18

Please sign in to comment.