Skip to content

Commit bee7a9b

Browse files
committed
fixup: Ensure virtuous xfer test checks for ongoing blocks first
1 parent bb20c3e commit bee7a9b

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

tests/e2e/e2e.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const (
2929
// unlikely to induce flaking due to unexpected resource
3030
// contention.
3131
DefaultTimeout = 2 * time.Minute
32+
33+
// Interval appropriate for network operations that should be
34+
// retried periodically but not too often.
35+
DefaultPollingInterval = 1 * time.Millisecond
3236
)
3337

3438
// Env is used to access shared test fixture. Intended to be

tests/e2e/x/transfer/virtuous.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
4646
func() {
4747
rpcEps := e2e.Env.URIs
4848

49+
// Waiting for ongoing blocks to have completed before starting this
50+
// test avoids the case of a previous test having initiated block
51+
// processing but not having completed it.
52+
gomega.Eventually(func() bool {
53+
allNodeMetrics, err := tests.GetMetricsForNodes(rpcEps, metricBlksProcessing)
54+
gomega.Expect(err).Should(gomega.BeNil())
55+
for _, metrics := range allNodeMetrics {
56+
if metrics[metricBlksProcessing] > 0 {
57+
return false
58+
}
59+
}
60+
return true
61+
}).
62+
WithTimeout(e2e.DefaultTimeout).
63+
WithPolling(e2e.DefaultPollingInterval).
64+
Should(gomega.BeTrue(), "The cluster is generating ongoing blocks. Is this test being run in parallel?")
65+
4966
allMetrics := []string{
5067
metricBlksProcessing,
5168
metricBlksAccepted,
@@ -93,20 +110,10 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
93110
)
94111
}
95112

96-
// URI -> "metric name" -> "metric value"
97-
metricsBeforeTx := make(map[string]map[string]float64)
98-
for _, u := range rpcEps {
99-
ep := u + "/ext/metrics"
100-
101-
mm, err := tests.GetMetricsValue(ep, allMetrics...)
102-
gomega.Expect(err).Should(gomega.BeNil())
103-
tests.Outf("{{green}}metrics at %q:{{/}} %v\n", ep, mm)
104-
105-
if mm[metricBlksProcessing] > 0 {
106-
ginkgo.Fail("%s the cluster has already ongoing blocks. Is this test being run in parallel?")
107-
}
108-
109-
metricsBeforeTx[u] = mm
113+
metricsBeforeTx, err := tests.GetMetricsForNodes(rpcEps, allMetrics...)
114+
gomega.Expect(err).Should(gomega.BeNil())
115+
for _, uri := range rpcEps {
116+
tests.Outf("{{green}}metrics at %q:{{/}} %v\n", uri, metricsBeforeTx[uri])
110117
}
111118

112119
testBalances := make([]uint64, 0)
@@ -249,8 +256,7 @@ RECEIVER NEW BALANCE (AFTER) : %21d AVAX
249256
gomega.Expect(err).Should(gomega.BeNil())
250257
gomega.Expect(status).Should(gomega.Equal(choices.Accepted))
251258

252-
ep := u + "/ext/metrics"
253-
mm, err := tests.GetMetricsValue(ep, allMetrics...)
259+
mm, err := tests.GetMetricsForNode(u, allMetrics...)
254260
gomega.Expect(err).Should(gomega.BeNil())
255261

256262
prev := metricsBeforeTx[u]

tests/http.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ import (
1313
"strings"
1414
)
1515

16+
// "metric name" -> "metric value"
17+
type NodeMetrics map[string]float64
18+
19+
// URI -> "metric name" -> "metric value"
20+
type NodesMetrics map[string]NodeMetrics
21+
22+
// GetMetricsForNode retrieves the specified metrics the provided node URI.
23+
func GetMetricsForNode(nodeURI string, metricNames ...string) (NodeMetrics, error) {
24+
uri := nodeURI + "/ext/metrics"
25+
return GetMetricsValue(uri, metricNames...)
26+
}
27+
28+
// GetMetricsForNodes retrieves the specified metrics for the provided node URIs.
29+
func GetMetricsForNodes(nodeURIs []string, metricNames ...string) (NodesMetrics, error) {
30+
metrics := make(NodesMetrics)
31+
for _, u := range nodeURIs {
32+
var err error
33+
metrics[u], err = GetMetricsForNode(u, metricNames...)
34+
if err != nil {
35+
return nil, fmt.Errorf("failed to retrieve metrics for %s: %w", u, err)
36+
}
37+
}
38+
return metrics, nil
39+
}
40+
1641
func GetMetricsValue(url string, metrics ...string) (map[string]float64, error) {
1742
lines, err := getHTTPLines(url)
1843
if err != nil {

0 commit comments

Comments
 (0)