-
Notifications
You must be signed in to change notification settings - Fork 28
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
test: grpc_client_test and fix grpc_client StopForError()
hang bug
#155
Merged
jinsan-line
merged 1 commit into
Finschia:feat/perf
from
jinsan-line:abci-grpc-client-test
Dec 29, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package abcicli_test | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
abcicli "github.com/tendermint/tendermint/abci/client" | ||
"github.com/tendermint/tendermint/abci/server" | ||
"github.com/tendermint/tendermint/abci/types" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
"github.com/tendermint/tendermint/libs/service" | ||
) | ||
|
||
type errorStopper interface { | ||
StopForError(error) | ||
} | ||
|
||
func TestSocketClientStopForErrorDeadlock(t *testing.T) { | ||
c := abcicli.NewGRPCClient(":80", false).(errorStopper) | ||
err := errors.New("foo-tendermint") | ||
|
||
// See Issue https://github.com/tendermint/abci/issues/114 | ||
doneChan := make(chan bool) | ||
go func() { | ||
defer close(doneChan) | ||
c.StopForError(err) | ||
c.StopForError(err) | ||
}() | ||
|
||
select { | ||
case <-doneChan: | ||
case <-time.After(time.Second * 4): | ||
t.Fatalf("Test took too long, potential deadlock still exists") | ||
} | ||
} | ||
|
||
func TestProperSyncCalls(t *testing.T) { | ||
app := slowApp{} | ||
|
||
s, c := setupClientServer(t, app) | ||
defer s.Stop() | ||
defer c.Stop() | ||
|
||
resp := make(chan error, 1) | ||
go func() { | ||
// This is BeginBlockSync unrolled.... | ||
reqres := c.BeginBlockAsync(types.RequestBeginBlock{}) | ||
c.FlushSync() | ||
res := reqres.Response.GetBeginBlock() | ||
require.NotNil(t, res) | ||
resp <- c.Error() | ||
}() | ||
|
||
select { | ||
case <-time.After(time.Second): | ||
require.Fail(t, "No response arrived") | ||
case err, ok := <-resp: | ||
require.True(t, ok, "Must not close channel") | ||
assert.NoError(t, err, "This should return success") | ||
} | ||
} | ||
|
||
func setupClientServer(t *testing.T, app types.Application) ( | ||
service.Service, abcicli.Client) { | ||
// some port between 20k and 30k | ||
port := 20000 + tmrand.Int32()%10000 | ||
addr := fmt.Sprintf("localhost:%d", port) | ||
|
||
s, err := server.NewServer(addr, "grpc", app) | ||
require.NoError(t, err) | ||
err = s.Start() | ||
require.NoError(t, err) | ||
|
||
c := abcicli.NewGRPCClient(addr, true) | ||
err = c.Start() | ||
require.NoError(t, err) | ||
|
||
return s, c | ||
} | ||
|
||
type slowApp struct { | ||
types.BaseApplication | ||
} | ||
|
||
func (slowApp) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { | ||
time.Sleep(200 * time.Millisecond) | ||
return types.ResponseBeginBlock{} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
cli.IsRunning()
andcli.Stop()
should be protected by the mutex. Otherwise, the error might be overwritten by a concurrent thread.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 had same thoughts when I met this issue first. But, I choose current implementation because,
socket_client
. (I've updated it in PR description)IsRunning()
andStop()
are not protected by the mutex but I realize that they are already atomic.Reference:
https://github.com/line/tendermint/blob/a01efd28c7257d3b056d1fcf263d39ccea3c1273/libs/service/service.go#L202-L206
https://github.com/line/tendermint/blob/a01efd28c7257d3b056d1fcf263d39ccea3c1273/libs/service/service.go#L159-L175
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.
OK, I understand.
There is a trivial problem that
Stopping abci.grpcClient for error: ...
log message might be written twice by two separate concurrent threads, but it's OK.