Skip to content

Commit

Permalink
Merge pull request #1005 from qazwsxedckll/fix-retry-count
Browse files Browse the repository at this point in the history
Fix retry count
  • Loading branch information
rogeralsing authored Dec 27, 2023
2 parents 8623ab9 + f18daa7 commit ed887f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
22 changes: 10 additions & 12 deletions cluster/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cluster

import (
"context"
"fmt"
"sync"
"testing"
Expand Down Expand Up @@ -112,11 +113,11 @@ func newClusterForTest(name string, cp ClusterProvider, opts ...ConfigOption) *C
c.MemberList = NewMemberList(c)
c.Config.RequestTimeoutTime = 1 * time.Second
c.Remote = remote.NewRemote(system, c.Config.RemoteConfig)
c.IdentityLookup = &lookup
return c
}

func TestCluster_Call(t *testing.T) {
t.Skipf("Maintaining")
assert := assert.New(t)

members := Members{
Expand All @@ -132,19 +133,10 @@ func TestCluster_Call(t *testing.T) {
t.Run("invalid kind", func(t *testing.T) {
msg := struct{}{}
resp, err := c.Request("name", "nonkind", &msg)
assert.Equal(remote.ErrUnAvailable, err)
assert.ErrorContains(err, "max retries")
assert.Nil(resp)
})

// FIXME: testcase
// t.Run("timeout", func(t *testing.T) {
// msg := struct{}{}
// callopts := NewGrainCallOptions(c).WithRetryCount(2).WithRequestTimeout(1 * time.Second)
// resp, err := c.Call("name", "kind", &msg, callopts)
// assert.Equalf(Remote.ErrUnknownError, err, "%v", err)
// assert.Nil(resp)
// })

testProps := actor.PropsFromFunc(
func(context actor.Context) {
switch msg := context.Message().(type) {
Expand All @@ -162,7 +154,13 @@ func TestCluster_Call(t *testing.T) {
assert.NoError(err)
assert.Equal(&struct{ Code int }{9528}, resp)
})
// t.Fatalf("need more testcases for cluster.Call")

t.Run("timeout", func(t *testing.T) {
msg := struct{}{}
resp, err := c.Request("name", "kind", &msg, WithTimeout(time.Millisecond))
assert.ErrorIs(err, context.DeadlineExceeded)
assert.Nil(resp)
})
}

func TestCluster_Get(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions cluster/default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ selectloop:

break selectloop
default:
if counter >= callConfig.RetryCount {
err = fmt.Errorf("have reached max retries: %v", callConfig.RetryCount)

break selectloop
}
pid := dcc.getPid(identity, kind)
if pid == nil {
dcc.cluster.Logger().Debug("Requesting PID from IdentityLookup but got nil", slog.String("identity", identity), slog.String("kind", kind))
Expand Down Expand Up @@ -130,6 +135,10 @@ func (dcc *DefaultContext) RequestFuture(identity string, kind string, message i
err := fmt.Errorf("request failed: %w", ctx.Err())
return nil, err
default:
if counter >= callConfig.RetryCount {
return nil, fmt.Errorf("have reached max retries: %v", callConfig.RetryCount)
}

pid := dcc.getPid(identity, kind)
if pid == nil {
dcc.cluster.Logger().Debug("Requesting PID from IdentityLookup but got nil", slog.String("identity", identity), slog.String("kind", kind))
Expand Down
4 changes: 2 additions & 2 deletions cluster/grain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func DefaultGrainCallConfig(cluster *Cluster) *GrainCallConfig {

func NewGrainCallOptions(cluster *Cluster) *GrainCallConfig {
return &GrainCallConfig{
//TODO: set default in config
RetryCount: 10,
// TODO: set default in config
RetryCount: 3,
Context: cluster.ActorSystem.Root,
Timeout: cluster.Config.RequestTimeoutTime,
RetryAction: func(i int) int {
Expand Down

0 comments on commit ed887f4

Please sign in to comment.