Skip to content

Commit 19ccc50

Browse files
committed
fixup: respond to review feedback #3
1 parent 60214e8 commit 19ccc50

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

tests/e2e/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ ginkgo -v ./tests/e2e -- \
7171
--use-persistent-network \
7272
--network-dir=/path/to/network
7373

74-
# Also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path
75-
# Also possible to set the TESTNETCTL_NETWORK_DIR env var instead of supplying --network-dir
74+
# It is also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path
75+
# and to set TESTNETCTL_NETWORK_DIR instead of supplying --network-dir.
7676
```
7777

7878
See the testnet fixture [README](../fixture/testnet/README.md) for more details.

tests/e2e/x/transfer/virtuous.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
5050
// test avoids the case of a previous test having initiated block
5151
// processing but not having completed it.
5252
gomega.Eventually(func() bool {
53-
allNodeMetrics, err := tests.GetMetricsForNodes(rpcEps, metricBlksProcessing)
53+
allNodeMetrics, err := tests.GetNodesMetrics(rpcEps, metricBlksProcessing)
5454
gomega.Expect(err).Should(gomega.BeNil())
5555
for _, metrics := range allNodeMetrics {
5656
if metrics[metricBlksProcessing] > 0 {
@@ -110,7 +110,7 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
110110
)
111111
}
112112

113-
metricsBeforeTx, err := tests.GetMetricsForNodes(rpcEps, allMetrics...)
113+
metricsBeforeTx, err := tests.GetNodesMetrics(rpcEps, allMetrics...)
114114
gomega.Expect(err).Should(gomega.BeNil())
115115
for _, uri := range rpcEps {
116116
tests.Outf("{{green}}metrics at %q:{{/}} %v\n", uri, metricsBeforeTx[uri])
@@ -256,7 +256,7 @@ RECEIVER NEW BALANCE (AFTER) : %21d AVAX
256256
gomega.Expect(err).Should(gomega.BeNil())
257257
gomega.Expect(status).Should(gomega.Equal(choices.Accepted))
258258

259-
mm, err := tests.GetMetricsForNode(u, allMetrics...)
259+
mm, err := tests.GetNodeMetrics(u, allMetrics...)
260260
gomega.Expect(err).Should(gomega.BeNil())
261261

262262
prev := metricsBeforeTx[u]

tests/fixture/test_data_server.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"net"
1313
"net/http"
14+
"net/url"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -39,7 +40,7 @@ type testDataServer struct {
3940
TestData
4041

4142
// Synchronizes access to test data
42-
mutex sync.Mutex
43+
lock sync.Mutex
4344
}
4445

4546
// Type used to marshal/unmarshal a set of test keys for transmission over http.
@@ -63,8 +64,8 @@ func (s *testDataServer) allocateKeys(w http.ResponseWriter, r *http.Request) {
6364
}
6465

6566
// Ensure a key will be allocated at most once
66-
s.mutex.Lock()
67-
defer s.mutex.Unlock()
67+
s.lock.Lock()
68+
defer s.lock.Unlock()
6869

6970
// Only fulfill requests for available keys
7071
if keyCount > len(s.FundedKeys) {
@@ -111,6 +112,7 @@ func ServeTestData(testData TestData) (string, error) {
111112
}
112113

113114
go func() {
115+
// Serve always returns a non-nil error and closes l.
114116
if err := httpServer.Serve(listener); err != http.ErrServerClosed {
115117
panic(fmt.Sprintf("unexpected error closing test data server: %v", err))
116118
}
@@ -121,12 +123,19 @@ func ServeTestData(testData TestData) (string, error) {
121123

122124
// Retrieve the specified number of funded test keys from the provided URI. A given
123125
// key is allocated at most once during the life of the test data server.
124-
func AllocateFundedKeys(uri string, count int) ([]*secp256k1.PrivateKey, error) {
126+
func AllocateFundedKeys(baseURI string, count int) ([]*secp256k1.PrivateKey, error) {
125127
if count <= 0 {
126128
return nil, errInvalidKeyCount
127129
}
128-
query := fmt.Sprintf("%s%s?%s=%d", uri, allocateKeysPath, keyCountParameterName, count)
129-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, query, nil)
130+
uri, err := url.Parse(baseURI)
131+
if err != nil {
132+
return nil, fmt.Errorf("failed to parse uri: %w", err)
133+
}
134+
uri.RawQuery = url.Values{
135+
keyCountParameterName: {strconv.Itoa(count)},
136+
}.Encode()
137+
uri.Path = allocateKeysPath
138+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, uri.String(), nil)
130139
if err != nil {
131140
return nil, fmt.Errorf("failed to construct request: %w", err)
132141
}

tests/http.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ type NodeMetrics map[string]float64
1919
// URI -> "metric name" -> "metric value"
2020
type NodesMetrics map[string]NodeMetrics
2121

22-
// GetMetricsForNode retrieves the specified metrics the provided node URI.
23-
func GetMetricsForNode(nodeURI string, metricNames ...string) (NodeMetrics, error) {
22+
// GetNodeMetrics retrieves the specified metrics the provided node URI.
23+
func GetNodeMetrics(nodeURI string, metricNames ...string) (NodeMetrics, error) {
2424
uri := nodeURI + "/ext/metrics"
2525
return GetMetricsValue(uri, metricNames...)
2626
}
2727

28-
// GetMetricsForNodes retrieves the specified metrics for the provided node URIs.
29-
func GetMetricsForNodes(nodeURIs []string, metricNames ...string) (NodesMetrics, error) {
28+
// GetNodesMetrics retrieves the specified metrics for the provided node URIs.
29+
func GetNodesMetrics(nodeURIs []string, metricNames ...string) (NodesMetrics, error) {
3030
metrics := make(NodesMetrics)
3131
for _, u := range nodeURIs {
3232
var err error
33-
metrics[u], err = GetMetricsForNode(u, metricNames...)
33+
metrics[u], err = GetNodeMetrics(u, metricNames...)
3434
if err != nil {
3535
return nil, fmt.Errorf("failed to retrieve metrics for %s: %w", u, err)
3636
}

0 commit comments

Comments
 (0)