routing/test: expose full list of htlc attempts
This commit is contained in:
parent
b13616a593
commit
3c6e4612ff
@ -68,10 +68,19 @@ func newIntegratedRoutingContext(t *testing.T) *integratedRoutingContext {
|
||||
return &ctx
|
||||
}
|
||||
|
||||
// htlcAttempt records the route and outcome of an attempted htlc.
|
||||
type htlcAttempt struct {
|
||||
route *route.Route
|
||||
success bool
|
||||
}
|
||||
|
||||
// testPayment launches a test payment and asserts that it is completed after
|
||||
// the expected number of attempts.
|
||||
func (c *integratedRoutingContext) testPayment(expectedNofAttempts int) {
|
||||
var nextPid uint64
|
||||
func (c *integratedRoutingContext) testPayment() []htlcAttempt {
|
||||
var (
|
||||
nextPid uint64
|
||||
attempts []htlcAttempt
|
||||
)
|
||||
|
||||
// Create temporary database for mission control.
|
||||
file, err := ioutil.TempFile("", "*.db")
|
||||
@ -147,8 +156,14 @@ func (c *integratedRoutingContext) testPayment(expectedNofAttempts int) {
|
||||
c.t.Fatal(err)
|
||||
}
|
||||
|
||||
success := htlcResult.failure == nil
|
||||
attempts = append(attempts, htlcAttempt{
|
||||
route: route,
|
||||
success: success,
|
||||
})
|
||||
|
||||
// Process the result.
|
||||
if htlcResult.failure == nil {
|
||||
if success {
|
||||
err := mc.ReportPaymentSuccess(pid, route)
|
||||
if err != nil {
|
||||
c.t.Fatal(err)
|
||||
@ -177,11 +192,9 @@ func (c *integratedRoutingContext) testPayment(expectedNofAttempts int) {
|
||||
}
|
||||
}
|
||||
|
||||
c.t.Logf("Payment attempts: %v\n", nextPid)
|
||||
if expectedNofAttempts != int(nextPid) {
|
||||
c.t.Fatalf("expected %v attempts, but needed %v",
|
||||
expectedNofAttempts, nextPid)
|
||||
}
|
||||
c.t.Logf("Payment attempts: %v\n", len(attempts))
|
||||
|
||||
return attempts
|
||||
}
|
||||
|
||||
// getNodeIndex returns the zero-based index of the given node in the route.
|
||||
|
@ -47,11 +47,17 @@ func TestProbabilityExtrapolation(t *testing.T) {
|
||||
// a specific number of attempts to safe-guard against accidental
|
||||
// modifications anywhere in the chain of components that is involved in
|
||||
// this test.
|
||||
ctx.testPayment(5)
|
||||
attempts := ctx.testPayment()
|
||||
if len(attempts) != 5 {
|
||||
t.Fatalf("expected 5 attempts, but needed %v", len(attempts))
|
||||
}
|
||||
|
||||
// If we use a static value for the node probability (no extrapolation
|
||||
// of data from other channels), all ten bad channels will be tried
|
||||
// first before switching to the paid channel.
|
||||
ctx.mcCfg.AprioriWeight = 1
|
||||
ctx.testPayment(11)
|
||||
attempts = ctx.testPayment()
|
||||
if len(attempts) != 11 {
|
||||
t.Fatalf("expected 11 attempts, but needed %v", len(attempts))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user