-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
tools: Fix tm bench quit #2405
tools: Fix tm bench quit #2405
Conversation
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
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.
Thanks for contributing to Tendermint. A few changes must be made before merging. NOTE you can setup gofmt to automatically format your code in almost any popular editor https://robots.thoughtbot.com/writing-go-in-vim https://atom.io/packages/go-plus https://github.com/microsoft/vscode-go
tools/tm-bench/main.go
Outdated
@@ -173,3 +177,13 @@ func startTransacters( | |||
|
|||
return transacters | |||
} | |||
|
|||
// RunForever waits for an interrupt signal and stops the node. | |||
func catchInterrupt(transacters []*transacter) { |
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.
formatting is off (please use https://golang.org/cmd/gofmt/)
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'm surprised this wasn't caught by linting. We should probably consider adding a second step then, like we do in the SDK, to make sure gofmt is correct.
tools/tm-bench/main.go
Outdated
|
||
// RunForever waits for an interrupt signal and stops the node. | ||
func catchInterrupt(transacters []*transacter) { | ||
// Sleep forever and then... |
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.
please remove (comment is useless)
tools/tm-bench/main.go
Outdated
func catchInterrupt(transacters []*transacter) { | ||
// Sleep forever and then... | ||
cmn.TrapSignal(func() { | ||
for _,e := range transacters { |
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.
e
-> t
tools/tm-bench/main.go
Outdated
@@ -93,6 +94,9 @@ Examples: | |||
"broadcast_tx_"+broadcastTxMethod, | |||
) | |||
|
|||
//catch Interrupt and quit tm-bench | |||
go catchInterrupt(transacters) |
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'd remove catchInterrupt altogether and just call
go cmn.TrapSignal(func() {
...
}
why need in intermediate function?
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.
Thanks for your review! All was done according to your nice advice.
tools/tm-bench/main.go
Outdated
@@ -93,6 +94,13 @@ Examples: | |||
"broadcast_tx_"+broadcastTxMethod, | |||
) | |||
|
|||
//catch Interrupt and quit tm-bench | |||
go cmn.TrapSignal(func() { |
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.
It doesn't seem advisable to further use this method, it logs uncontrolled and the functionality is simple enough that it could be copied as is.
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 do agree, but I think we can remove all the cmn.TrapSignals at once in a separate PR.
Its already written, who knows when we're going to get to deleting / refactoring the trap signal logic.
Codecov Report
@@ Coverage Diff @@
## develop #2405 +/- ##
===========================================
- Coverage 60.99% 60.96% -0.03%
===========================================
Files 197 197
Lines 16313 16320 +7
===========================================
Hits 9950 9950
- Misses 5496 5505 +9
+ Partials 867 865 -2
|
@@ -93,6 +95,19 @@ Examples: | |||
"broadcast_tx_"+broadcastTxMethod, | |||
) | |||
|
|||
//catch Interrupt and quit tm-bench |
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 this comment is needed
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.
Should be removed or have proper form of: Catch interrupt and quit.
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.
Some style and functional changes needed.
@@ -12,6 +12,8 @@ import ( | |||
|
|||
"github.com/tendermint/tendermint/libs/log" | |||
tmrpc "github.com/tendermint/tendermint/rpc/client" | |||
"os/signal" | |||
"syscall" |
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.
Import order is as follows:
import (
// stdlib
// external packages
// internal packages
)
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 wonder if we can capture this in the linter ?!
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 wrote this so many times by now, was wondering the same.
@@ -93,6 +95,19 @@ Examples: | |||
"broadcast_tx_"+broadcastTxMethod, | |||
) | |||
|
|||
//catch Interrupt and quit tm-bench |
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.
Should be removed or have proper form of: Catch interrupt and quit.
@@ -93,6 +95,19 @@ Examples: | |||
"broadcast_tx_"+broadcastTxMethod, | |||
) | |||
|
|||
//catch Interrupt and quit tm-bench | |||
go func() { |
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.
This should be moved up, before the first side-effectful call on line 86. It also doesn't need to be wrapped in a goroutine entirely, only the part which ranges over the channel.
for _, t := range transacters { | ||
t.Stop() | ||
} | ||
os.Exit(1) |
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.
Is it an error if the user quits on purpose? Would challenge that and rethink if the binary exit with an error code.
@bradyjoestar Gentle ping on this. Would you be able to address the latest comments? Then it should be good to go. |
* specify time unit for FlushThrottleTimeout in TestP2PConfig Refs #2555 * [tm-bench] refactor code #2405 (review)
refs #2369