Skip to content

Commit

Permalink
Add registration time for refresh (#1184)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art authored Dec 2, 2021
1 parent 404ad8a commit 292c0c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/registry/common/refresh/nse_registry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (c *refreshNSEClient) Register(ctx context.Context, nse *registry.NetworkSe
if reg.ExpirationTime != nil {
refreshNSE := nse.Clone()
refreshNSE.ExpirationTime = reg.ExpirationTime
refreshNSE.InitialRegistrationTime = reg.InitialRegistrationTime

cancel, err = c.startRefresh(ctx, refreshNSE, expirationDuration)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions pkg/registry/common/refresh/nse_registry_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,46 @@ func Test_RefreshNSEClient_SetsCorrectExpireTime(t *testing.T) {
require.NoError(t, err)
}

func Test_RefreshNSEClient_CorrectInitialRegTime(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

clockMock := clockmock.New(ctx)
ctx = clock.WithClock(ctx, clockMock)
regTime := clockMock.Now()

var registerCount int32

client := next.NewNetworkServiceEndpointRegistryClient(
serialize.NewNetworkServiceEndpointRegistryClient(),
refresh.NewNetworkServiceEndpointRegistryClient(ctx),
&injectNSERegisterClient{
NetworkServiceEndpointRegistryClient: null.NewNetworkServiceEndpointRegistryClient(),
register: func(c context.Context, nse *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) {
require.NotNil(t, nse.InitialRegistrationTime)
require.True(t, nse.InitialRegistrationTime.AsTime().Equal(regTime))
atomic.AddInt32(&registerCount, 1)
return next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, nse, opts...)
},
},
)

nse := testNSE(clockMock)
nse.InitialRegistrationTime = timestamppb.New(regTime)
reg, err := client.Register(ctx, nse)
require.NoError(t, err)

clockMock.Add(expireTimeout)
require.Eventually(t, func() bool {
return atomic.LoadInt32(&registerCount) > 1
}, testWait, testTick)

_, err = client.Unregister(ctx, reg)
require.NoError(t, err)
}

type requestCountClient struct {
requestCount int32

Expand Down

0 comments on commit 292c0c4

Please sign in to comment.