-
Notifications
You must be signed in to change notification settings - Fork 12
/
metrics_test.go
50 lines (40 loc) · 1.67 KB
/
metrics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package e2e
import (
"github.com/orbs-network/orbs-network-go/instrumentation/metric"
"github.com/orbs-network/orbs-network-go/services/blockstorage"
"github.com/stretchr/testify/require"
"io/ioutil"
"net/http"
"testing"
)
func TestE2E_Metrics(t *testing.T) {
h := NewAppHarness()
if h.config.RemoteEnvironment {
t.Skip("Skipping E2E metrics is only for local testing")
}
h.WaitUntilTransactionPoolIsReady(t) // warm up
// check reading status.json
res, err := http.Get(h.config.AppChainUrl + "/status")
require.NoError(t, err, "should succeed reading status endpoint")
require.NotNil(t, res, "status should not be empty")
readBytes, _ := ioutil.ReadAll(res.Body)
localWrite(t, readBytes, "status.json")
// check reading of metrics.json
res, err = http.Get(h.metricsUrl)
require.NoError(t, err, "should succeed reading metrics endpoint")
require.NotNil(t, res, "metrics should not be empty")
readBytes, _ = ioutil.ReadAll(res.Body)
localWrite(t, readBytes, "metrics.json")
// check reader
metricReader, err := metric.NewReader(h.metricsUrl)
require.NoError(t, err, "should succeed reading metrics back into map")
require.NotEqual(t, 0, len(metricReader), "should not be empty")
blockHeight, found := metricReader.GetAsInt(blockstorage.MetricBlockHeight)
require.True(t, found, "block height should be found")
require.True(t, blockHeight > int64(CannedBlocksFileMinHeight))
}
func localWrite(t *testing.T, data []byte, filename string) {
// uncomment to save the values to a file for visual testing
//err := ioutil.WriteFile(filepath.Join(config.GetCurrentSourceFileDirPath(), "_data", filename), data, 0666)
//require.NoError(t, err, "should be able to write a file")
}