Skip to content

Commit

Permalink
vet #1
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Mar 16, 2020
1 parent ce3de81 commit ed4745a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
7 changes: 3 additions & 4 deletions balancer/rls/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ func TestLookupSuccess(t *testing.T) {
defer cleanup()

const (
defaultTestTimeout = 1 * time.Second
rlsReqPath = "/service/method"
rlsRespTarget = "us_east_1.firestore.googleapis.com"
rlsHeaderData = "headerData"
rlsReqPath = "/service/method"
rlsRespTarget = "us_east_1.firestore.googleapis.com"
rlsHeaderData = "headerData"
)

rlsReqKeyMap := map[string]string{
Expand Down
63 changes: 30 additions & 33 deletions balancer/rls/internal/picker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import (
"google.golang.org/grpc/metadata"
)

const (
defaultTestTimeout = 1 * time.Second
maxAge = 5 * time.Second
)
const defaultTestMaxAge = 5 * time.Second

func initKeyBuilderMap() (keys.BuilderMap, error) {
kb1 := &rlspb.GrpcKeyBuilder{
Expand Down Expand Up @@ -124,8 +121,8 @@ func TestPickKeyBuilder(t *testing.T) {

now := time.Now()
return &cache.Entry{
ExpiryTime: now.Add(maxAge),
StaleTime: now.Add(maxAge),
ExpiryTime: now.Add(defaultTestMaxAge),
StaleTime: now.Add(defaultTestMaxAge),
// Cache entry is configured with a child policy whose
// picker always returns an empty PickResult and nil
// error.
Expand Down Expand Up @@ -271,23 +268,23 @@ func TestPick(t *testing.T) {
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_throttled_defaultTargetOnMiss",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
throttle: true, // Proactive refresh is throttled.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_throttled_clientSeesError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
throttle: true, // Proactive refresh is throttled.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_throttled_defaultTargetOnError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
throttle: true, // Proactive refresh is throttled.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR,
Expand Down Expand Up @@ -317,46 +314,46 @@ func TestPick(t *testing.T) {
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_notThrottled_defaultTargetOnMiss",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
newRLSRequest: true, // Proactive refresh.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_notThrottled_clientSeesError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
newRLSRequest: true, // Proactive refresh.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boExpired_dataNotExpired_notThrottled_defaultTargetOnError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
newRLSRequest: true, // Proactive refresh.
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boNotExpired_dataExpired_defaultTargetOnError",
cacheEntry: &cache.Entry{BackoffTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{BackoffTime: time.Now().Add(defaultTestMaxAge)},
useDefaultPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boNotExpired_dataExpired_defaultTargetOnMiss",
cacheEntry: &cache.Entry{BackoffTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{BackoffTime: time.Now().Add(defaultTestMaxAge)},
useDefaultPick: true,
strategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
wantErr: nil,
},
{
desc: "cacheHit_noPending_stale_boNotExpired_dataExpired_clientSeesError",
cacheEntry: &cache.Entry{
BackoffTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR,
Expand All @@ -365,8 +362,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_stale_boNotExpired_dataNotExpired_defaultTargetOnError",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
useChildPick: true,
Expand All @@ -376,8 +373,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_stale_boNotExpired_dataNotExpired_defaultTargetOnMiss",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
useChildPick: true,
Expand All @@ -387,8 +384,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_stale_boNotExpired_dataNotExpired_clientSeesError",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
useChildPick: true,
Expand All @@ -398,8 +395,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_notStale_dataNotExpired_defaultTargetOnError",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
StaleTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
StaleTime: time.Now().Add(defaultTestMaxAge),
},
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR,
Expand All @@ -408,8 +405,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_notStale_dataNotExpired_defaultTargetOnMiss",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
StaleTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
StaleTime: time.Now().Add(defaultTestMaxAge),
},
useChildPick: true,
strategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
Expand All @@ -418,8 +415,8 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_noPending_notStale_dataNotExpired_clientSeesError",
cacheEntry: &cache.Entry{
ExpiryTime: time.Now().Add(maxAge),
StaleTime: time.Now().Add(maxAge),
ExpiryTime: time.Now().Add(defaultTestMaxAge),
StaleTime: time.Now().Add(defaultTestMaxAge),
},
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR,
Expand Down Expand Up @@ -449,7 +446,7 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_pending_dataExpired_boNotExpired_defaultTargetOnError",
cacheEntry: &cache.Entry{
BackoffTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
useDefaultPick: true,
Expand All @@ -459,7 +456,7 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_pending_dataExpired_boNotExpired_defaultTargetOnMiss",
cacheEntry: &cache.Entry{
BackoffTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
pending: true,
Expand All @@ -470,7 +467,7 @@ func TestPick(t *testing.T) {
{
desc: "cacheHit_pending_dataExpired_boNotExpired_clientSeesError",
cacheEntry: &cache.Entry{
BackoffTime: time.Now().Add(maxAge),
BackoffTime: time.Now().Add(defaultTestMaxAge),
CallStatus: rlsLastErr,
},
pending: true,
Expand All @@ -479,23 +476,23 @@ func TestPick(t *testing.T) {
},
{
desc: "cacheHit_pending_dataNotExpired_defaultTargetOnError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
pending: true,
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR,
wantErr: nil,
},
{
desc: "cacheHit_pending_dataNotExpired_defaultTargetOnMiss",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
pending: true,
useChildPick: true,
strategy: rlspb.RouteLookupConfig_ASYNC_LOOKUP_DEFAULT_TARGET_ON_MISS,
wantErr: nil,
},
{
desc: "cacheHit_pending_dataNotExpired_clientSeesError",
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(maxAge)},
cacheEntry: &cache.Entry{ExpiryTime: time.Now().Add(defaultTestMaxAge)},
pending: true,
useChildPick: true,
strategy: rlspb.RouteLookupConfig_SYNC_LOOKUP_CLIENT_SEES_ERROR,
Expand Down

0 comments on commit ed4745a

Please sign in to comment.