-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fundingmanager test: poll or database state instead of using timeouts. #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fundingmanager test: poll or database state instead of using timeouts. #366
Conversation
fundingmanager_test.go
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
fundingmanager_test.go
Outdated
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🚶
fundingmanager_test.go
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
fundingmanager_test.go
Outdated
There was a problem hiding this comment.
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.
8e4a1f8
to
95393dd
Compare
There was a problem hiding this 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 :)
fundingmanager_test.go
Outdated
} | ||
|
||
// Try again in 500 ms. | ||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
fundingmanager_test.go
Outdated
There was a problem hiding this comment.
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?
fundingmanager_test.go
Outdated
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more than 80 chars?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, looks good!
fundingmanager_test.go
Outdated
} | ||
|
||
// Try again in 500 ms. | ||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
fundingmanager_test.go
Outdated
} | ||
|
||
// Sleep, and try again in a bit. | ||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
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
fundingmanager_test.go
Outdated
|
||
var state channelOpeningState | ||
var err error | ||
for i := 0; i < 10; i++ { |
There was a problem hiding this comment.
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?
Thanks @halseth, LGTM! 🎉😎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.