Skip to content

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Oct 3, 2017

This commits make the fundingmanager tests poll for database state
for a time, instead of using an explicit sleep before accessing the
DB. This should address some of the flakes encountered on Travis,
where db writes might take longer than usual.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible for err != nil given the checks above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would read a bit better as:

if err == ErrChannelNotFound {
    // Got expected state, return with success.
    return
} else if err != nil {
    t.Fatalf("unable to get channel state: %v", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have the same behavior as the current assertion? or are you suggesting to make them a single if-else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment initially was made in assertErrChannelNotFound and magically moved here after I made the change 🚶

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getChannelOpeningState returns state as markedOpen if there is an error, so we should not return if err == ErrChannelNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: num -> expectedNum

This commits make the fundingmanager tests poll for database state
for a time, instead of using an explicit sleep before accessing the
DB. This should address some of the flakes encountered on Travis,
where db writes might take longer than usual.
@halseth halseth force-pushed the funding-tests-db-read branch from 8e4a1f8 to 95393dd Compare October 20, 2017 08:25
@halseth
Copy link
Contributor Author

halseth commented Oct 20, 2017

Thanks for the review @jimpo! Addressed the comments, and should be ready for review/merge 🎊

PTAL.

cc @Roasbeef

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor, I like the consistency that this approach adds to our testing framework! A couple comments, but looks solid 🎉 The test cases are definitely simpler to interpret as a result :)

}

// Try again in 500 ms.
time.Sleep(500 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have the same behavior as the current assertion? or are you suggesting to make them a single if-else?

func assertNumPendingChannels(t *testing.T, node *testNode, expectedNum int) {
var numPendingChans int
for i := 0; i < 10; i++ {
pendingChannels, err := node.fundingMgr.cfg.Wallet.Cfg.Database.FetchPendingChannels()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more than 80 chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, not sure what's the best way to split such a line, but did my best now :b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, looks good!

}

// Try again in 500 ms.
time.Sleep(500 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}

// Sleep, and try again in a bit.
time.Sleep(500 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to sleep on the last iteration? another alternative is to sleep at the top of the loop if only if i > 0


var state channelOpeningState
var err error
for i := 0; i < 10; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to break out the default number of iterations and sleep duration as constants?

@cfromknecht
Copy link
Contributor

Thanks @halseth, LGTM! 🎉😎

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Roasbeef Roasbeef merged commit 4b883b9 into lightningnetwork:master Oct 25, 2017
@halseth halseth deleted the funding-tests-db-read branch July 12, 2018 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants