Skip to content

Commit

Permalink
Merge pull request #1159 from ydb-platform/start-stop
Browse files Browse the repository at this point in the history
rename lastUsage.Touch() => lastUsage.Start()
  • Loading branch information
asmyasnikov authored Mar 25, 2024
2 parents afd4228 + 8f774c7 commit 173e976
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions internal/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ func (c *conn) Invoke(
return c.wrapError(err)
}

defer c.lastUsage.Touch()()
stop := c.lastUsage.Start()
defer stop()

ctx, traceID, err := meta.TraceID(ctx)
if err != nil {
Expand Down Expand Up @@ -411,7 +412,8 @@ func (c *conn) NewStream(
return nil, c.wrapError(err)
}

defer c.lastUsage.Touch()()
stop := c.lastUsage.Start()
defer stop()

ctx, traceID, err := meta.TraceID(ctx)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions internal/conn/grpc_client_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (s *grpcClientStream) CloseSend() (err error) {
onDone(err)
}()

defer s.c.lastUsage.Touch()()
stop := s.c.lastUsage.Start()
defer stop()

err = s.ClientStream.CloseSend()

Expand Down Expand Up @@ -65,7 +66,8 @@ func (s *grpcClientStream) SendMsg(m interface{}) (err error) {
onDone(err)
}()

defer s.c.lastUsage.Touch()()
stop := s.c.lastUsage.Start()
defer stop()

err = s.ClientStream.SendMsg(m)

Expand Down Expand Up @@ -106,7 +108,8 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
onDone(err)
}()

defer s.c.lastUsage.Touch()()
stop := s.c.lastUsage.Start()
defer stop()

defer func() {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/conn/last_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (l *lastUsage) Get() time.Time {
return l.clock.Now()
}

func (l *lastUsage) Touch() (releaseFunc func()) {
func (l *lastUsage) Start() (stop func()) {
l.locks.Add(1)

return sync.OnceFunc(func() {
Expand Down
10 changes: 5 additions & 5 deletions internal/conn/last_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_lastUsage_Lock(t *testing.T) {
lu.t.Store(&start)
t1 := lu.Get()
require.Equal(t, start, t1)
f := lu.Touch()
f := lu.Start()
clock.Advance(time.Hour)
t2 := lu.Get()
require.Equal(t, start.Add(time.Hour), t2)
Expand All @@ -39,14 +39,14 @@ func Test_lastUsage_Lock(t *testing.T) {
lu.t.Store(&start)
t1 := lu.Get()
require.Equal(t, start, t1)
f1 := lu.Touch()
f1 := lu.Start()
clock.Advance(time.Hour)
t2 := lu.Get()
require.Equal(t, start.Add(time.Hour), t2)
f2 := lu.Touch()
f2 := lu.Start()
clock.Advance(time.Hour)
f1()
f3 := lu.Touch()
f3 := lu.Start()
clock.Advance(time.Hour)
t3 := lu.Get()
require.Equal(t, start.Add(3*time.Hour), t3)
Expand Down Expand Up @@ -83,7 +83,7 @@ func Test_lastUsage_Lock(t *testing.T) {
t2 := lu.Get()
require.Equal(t, start, t2)
clock.Advance(time.Hour)
defer lu.Touch()()
defer lu.Start()()
t3 := lu.Get()
require.Equal(t, start.Add(2*time.Hour), t3)
clock.Advance(time.Hour)
Expand Down

0 comments on commit 173e976

Please sign in to comment.