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

add unit test for history client #5841

Merged

Conversation

shijiesheng
Copy link
Member

What changed?

  • Added unit test
  • Refactored PeerResolver to interface for easier testing

Why?

improve test coverage

How did you test it?

Potential risks

Release notes

Documentation Changes

@shijiesheng shijiesheng enabled auto-merge (squash) April 2, 2024 20:55
@shijiesheng shijiesheng merged commit 57ac5a9 into cadence-workflow:master Apr 2, 2024
18 checks passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 018ea086-5071-4f5f-8be5-0c42f9c6dc5c

Details

  • 5 of 6 (83.33%) changed or added relevant lines in 1 file are covered.
  • 42 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.2%) to 65.763%

Changes Missing Coverage Covered Lines Changed/Added Lines %
client/history/peerResolver.go 5 6 83.33%
Files with Coverage Reduction New Missed Lines %
common/task/weighted_round_robin_task_scheduler.go 2 88.06%
common/task/parallel_task_processor.go 2 93.06%
service/history/task/timer_task_executor_base.go 2 78.38%
common/persistence/execution_manager.go 2 83.54%
common/util.go 2 91.78%
service/matching/taskListManager.go 2 80.2%
service/history/execution/mutable_state_util.go 2 78.13%
common/persistence/statsComputer.go 2 96.07%
common/task/fifo_task_scheduler.go 3 84.54%
service/history/shard/context.go 9 66.87%
Totals Coverage Status
Change from base Build 018ea085-2ea6-4c6f-9225-60496ba965f0: 0.2%
Covered Lines: 96237
Relevant Lines: 146339

💛 - Coveralls

numberOfShards int
resolver membership.Resolver
namedPort string // grpc or tchannel, depends on yarpc configuration
}

// NewPeerResolver creates a new history peer resolver.
func NewPeerResolver(numberOfShards int, resolver membership.Resolver, namedPort string) PeerResolver {
return PeerResolver{
return peerResolver{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change this to &peerResolver and attach the functions to the *peerResolver

@@ -29,15 +29,25 @@ import (
// PeerResolver is used to resolve history peers.
// Those are deployed instances of Cadence history services that participate in the cluster ring.
// The resulting peer is simply an address of form ip:port where RPC calls can be routed to.
type PeerResolver struct {
//
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination peerResolver_mock.go -package history github.com/uber/cadence/client/history PeerResolver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename this file to peer_resolver.go and the mock file to peer_resolver_test.go. we keep fixing naming inconsistencies as we touch

})
},
mock: func(p *MockPeerResolver, c *MockClient) {
p.EXPECT().FromShardID(123).Return("test-peer", nil).Times(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add more test cases to cover

  • peerResolver's corresponding method returning err causes client method to return err
  • mock client's corresponding method returning err causes client method to return err

otherwise there are plenty of code branches uncovered. https://app.codecov.io/github/uber/cadence/commit/eaacb01073f6fc3c844329d557b732f3102cc41b/blob/client/history/client.go

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.

4 participants