Skip to content

Commit 063ffe2

Browse files
committed
Feedback
1 parent 5b0c614 commit 063ffe2

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Diff for: services/horizon/internal/integration/protocol14_state_verifier_test.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
)
1616

17+
const (
18+
firstCheckpoint = (64 * (iota + 1)) - 1
19+
secondCheckpoint
20+
thirdCheckpoint
21+
)
22+
1723
func TestProtocol14StateVerifier(t *testing.T) {
1824
itest := integration.NewTest(t, protocol15Config)
1925

@@ -99,42 +105,43 @@ func TestProtocol14StateVerifier(t *testing.T) {
99105
assert.True(t, txResp.Successful)
100106

101107
// Wait for the first checkpoint ledger
102-
for !itest.LedgerIngested(63) {
103-
t.Log("First checkpoint ledger (63) not ingested yet...")
108+
for !itest.LedgerIngested(firstCheckpoint) {
109+
t.Log("First checkpoint ledger not ingested yet...")
104110
time.Sleep(5 * time.Second)
105111
}
106112

107-
verified := waitForStateVerifications(t, itest, 1)
113+
verified := waitForStateVerifications(itest, 1)
108114
if !verified {
109115
t.Fatal("State verification not run...")
110116
}
111117

112118
// Trigger state rebuild to check if ingesting from history archive works
113-
itest.RunHorizonCLICommand([]string{"expingest", "trigger-state-rebuild"})
119+
itest.RunHorizonCLICommand("expingest", "trigger-state-rebuild")
114120

115121
// Wait for the second checkpoint ledger and state rebuild
116-
for !itest.LedgerClosed(127) {
117-
t.Log("First checkpoint ledger (127) not closed yet...")
122+
for !itest.LedgerClosed(secondCheckpoint) {
123+
t.Log("Second checkpoint ledger not closed yet...")
118124
time.Sleep(5 * time.Second)
119125
}
120126

121127
// Wait for the third checkpoint ledger and state verification trigger
122-
for !itest.LedgerIngested(191) {
123-
t.Log("First checkpoint ledger (191) not ingested yet...")
128+
for !itest.LedgerIngested(thirdCheckpoint) {
129+
t.Log("Third checkpoint ledger not ingested yet...")
124130
time.Sleep(5 * time.Second)
125131
}
126132

127-
verified = waitForStateVerifications(t, itest, 2)
133+
verified = waitForStateVerifications(itest, 2)
128134
if !verified {
129135
t.Fatal("State verification not run...")
130136
}
131137
}
132138

133-
func waitForStateVerifications(t *testing.T, itest *integration.Test, count int) bool {
139+
func waitForStateVerifications(itest *integration.Test, count int) bool {
140+
t := itest.CurrentTest()
134141
// Check metrics until state verification run
135142
for i := 0; i < 120; i++ {
136143
t.Logf("Checking metrics (%d attempt)\n", i)
137-
res, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", itest.AdminPort()))
144+
res, err := http.Get(itest.MetricsURL())
138145
assert.NoError(t, err)
139146

140147
metricsBytes, err := ioutil.ReadAll(res.Body)

Diff for: services/horizon/internal/test/integration/integration.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ func (i *Test) AdminPort() int {
320320
return 6060
321321
}
322322

323+
// Metrics URL returns Horizon metrics URL.
324+
func (i *Test) MetricsURL() string {
325+
return fmt.Sprintf("http://localhost:%d/metrics", i.AdminPort())
326+
}
327+
323328
// Master returns a keypair of the network master account.
324329
func (i *Test) Master() *keypair.Full {
325330
return keypair.Master(NetworkPassphrase).(*keypair.Full)
@@ -639,7 +644,7 @@ func (i *Test) LogFailedTx(txResponse proto.Transaction, horizonResult error) {
639644
"Transaction doesn't have success code.")
640645
}
641646

642-
func (i *Test) RunHorizonCLICommand(cmd []string) {
647+
func (i *Test) RunHorizonCLICommand(cmd ...string) {
643648
fullCmd := append([]string{"/stellar/horizon/bin/horizon"}, cmd...)
644649
id, err := i.cli.ContainerExecCreate(
645650
context.Background(),

0 commit comments

Comments
 (0)