-
Notifications
You must be signed in to change notification settings - Fork 929
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
Imp: Zk client #601
Imp: Zk client #601
Conversation
Codecov Report
@@ Coverage Diff @@
## feature/dubbo-2.7.5 #601 +/- ##
=======================================================
- Coverage 66.16% 65.78% -0.38%
=======================================================
Files 204 204
Lines 10610 10604 -6
=======================================================
- Hits 7020 6976 -44
- Misses 2912 2951 +39
+ Partials 678 677 -1
Continue to review full report at Codecov.
|
remoting/zookeeper/client_test.go
Outdated
"testing" | ||
"time" | ||
) | ||
|
||
import ( | ||
"github.com/dubbogo/go-zookeeper/zk" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" |
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 u can rollback the testify/require to testify/assert package.
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.
an example
func TestSomething(t *testing.T) {
var err error
err = perrors.Errorf("something1")
assert.NoError(t, err)
err = perrors.Errorf("something2")
assert.NoError(t, err)
}
- use
testify/assert
will output two errors on console:
=== RUN TestSomething
--- FAIL: TestSomething (0.00s)
client_test.go:151:
Error Trace: client_test.go:151
Error: Received unexpected error:
something1
github.com/apache/dubbo-go/remoting/zookeeper.TestSomething
D:/GoPath/src/github.com/apache/dubbo-go/remoting/zookeeper/client_test.go:150
testing.tRunner
D:/Go/src/testing/testing.go:909
runtime.goexit
D:/Go/src/runtime/asm_amd64.s:1357
Test: TestSomething
client_test.go:154:
Error Trace: client_test.go:154
Error: Received unexpected error:
something2
github.com/apache/dubbo-go/remoting/zookeeper.TestSomething
D:/GoPath/src/github.com/apache/dubbo-go/remoting/zookeeper/client_test.go:153
testing.tRunner
D:/Go/src/testing/testing.go:909
runtime.goexit
D:/Go/src/runtime/asm_amd64.s:1357
Test: TestSomething
FAIL
- use
testify/require
just output the first error and stop the test case intermediately
why I prefer testify/require
- Because errors in test case may have some dependency: first error causes second error, then I think it's better to use
testify/require
, which only shows the first error. - Using
testify/assert
may output too many errors, but developers only need to focus on fixing the first error.
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.
However, it is impossible that we test the same error case in one Testxxx.
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.
@AlexStocks Ok, I revert require
to assert
.
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
@@ -42,21 +42,23 @@ const ( | |||
) | |||
|
|||
var ( | |||
errNilZkClientConn = perrors.New("zookeeperclient{conn} is nil") | |||
errNilZkClientConn = perrors.New("zookeeper client{conn} is nil") | |||
errNilChildren = perrors.Errorf("has none children") | |||
errNilNode = perrors.Errorf("node does not exist") | |||
) | |||
|
|||
// ZookeeperClient ... |
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.
maybe u can add some comments for this struct or just using "nolint" instead.
What this PR does:
eventRegistry
inZookeeperClient
to avoid concurrent read and write in mapgithub.com/stretchr/testify/assert
withgithub.com/stretchr/testify/require
in test to fail test case immediately when test meet an error\n
in logSpecial notes for your reviewer:
Does this PR introduce a user-facing change?: