Skip to content
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

Merged
merged 7 commits into from
Jun 17, 2020
Merged

Imp: Zk client #601

merged 7 commits into from
Jun 17, 2020

Conversation

gaoxinge
Copy link

@gaoxinge gaoxinge commented Jun 11, 2020

What this PR does:

  • add lock for eventRegistry in ZookeeperClient to avoid concurrent read and write in map
  • replace github.com/stretchr/testify/assert with github.com/stretchr/testify/require in test to fail test case immediately when test meet an error
  • fix type and remove \n in log

Special notes for your reviewer:

  • NONE

Does this PR introduce a user-facing change?:

NONE

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2020

Codecov Report

Merging #601 into feature/dubbo-2.7.5 will decrease coverage by 0.37%.
The diff coverage is 72.91%.

Impacted file tree graph

@@                   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     
Impacted Files Coverage Δ
remoting/zookeeper/client.go 66.66% <72.91%> (-0.57%) ⬇️
metadata/report/delegate/delegate_report.go 30.76% <0.00%> (-10.00%) ⬇️
protocol/dubbo/pool.go 74.88% <0.00%> (-6.40%) ⬇️
protocol/dubbo/client.go 64.24% <0.00%> (-4.85%) ⬇️
cluster/cluster_impl/failback_cluster_invoker.go 78.49% <0.00%> (-2.16%) ⬇️
protocol/dubbo/listener.go 56.45% <0.00%> (-1.08%) ⬇️
remoting/kubernetes/listener.go 57.00% <0.00%> (+0.93%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 669301f...df758dc. Read the comment docs.

@AlexStocks AlexStocks requested review from pantianying and CodingSinger and removed request for pantianying June 12, 2020 02:00
"testing"
"time"
)

import (
"github.com/dubbogo/go-zookeeper/zk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
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 u can rollback the testify/require to testify/assert package.

Copy link
Author

@gaoxinge gaoxinge Jun 15, 2020

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.

@AlexStocks

Copy link
Contributor

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.

Copy link
Author

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.

@AlexStocks AlexStocks changed the title Zk client Imp: Zk client Jun 13, 2020
Copy link
Member

@pantianying pantianying left a 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 ...
Copy link
Contributor

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.

@AlexStocks AlexStocks merged commit 024f7b2 into apache:feature/dubbo-2.7.5 Jun 17, 2020
@gaoxinge gaoxinge deleted the zk_client branch June 26, 2020 01:22
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.

5 participants