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

Fix retry count #1005

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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