From 9290004bb8bb8032a8efb7a338c446ca111f7411 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 1 Jul 2016 16:22:51 +0100 Subject: [PATCH] pacer: make sleep get-able and set-able --- pacer/pacer.go | 15 +++++++++++++++ pacer/pacer_test.go | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/pacer/pacer.go b/pacer/pacer.go index 469012b77..6b959fa8e 100644 --- a/pacer/pacer.go +++ b/pacer/pacer.go @@ -76,6 +76,21 @@ func New() *Pacer { return p } +// SetSleep sets the current sleep time +func (p *Pacer) SetSleep(t time.Duration) *Pacer { + p.mu.Lock() + defer p.mu.Unlock() + p.sleepTime = t + return p +} + +// GetSleep gets the current sleep time +func (p *Pacer) GetSleep() time.Duration { + p.mu.Lock() + defer p.mu.Unlock() + return p.sleepTime +} + // SetMinSleep sets the minimum sleep time for the pacer func (p *Pacer) SetMinSleep(t time.Duration) *Pacer { p.mu.Lock() diff --git a/pacer/pacer_test.go b/pacer/pacer_test.go index 5219c0b85..435761166 100644 --- a/pacer/pacer_test.go +++ b/pacer/pacer_test.go @@ -51,6 +51,20 @@ func TestNew(t *testing.T) { } } +func TestSetSleep(t *testing.T) { + p := New().SetSleep(2 * time.Millisecond) + if p.sleepTime != 2*time.Millisecond { + t.Errorf("didn't set") + } +} + +func TestGetSleep(t *testing.T) { + p := New().SetSleep(2 * time.Millisecond) + if p.GetSleep() != 2*time.Millisecond { + t.Errorf("didn't get") + } +} + func TestSetMinSleep(t *testing.T) { p := New().SetMinSleep(1 * time.Millisecond) if p.minSleep != 1*time.Millisecond {