From 236a4d20c7cc4871011e8972961c9c2d13a3b1ca Mon Sep 17 00:00:00 2001 From: Yegor Myskin Date: Tue, 4 Jun 2019 01:48:24 +0300 Subject: [PATCH] Test --- rate_limiter_channel_test.go | 27 +++++++++++++++++++++++++++ seeker_test.go | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 rate_limiter_channel_test.go diff --git a/rate_limiter_channel_test.go b/rate_limiter_channel_test.go new file mode 100644 index 0000000..f62586c --- /dev/null +++ b/rate_limiter_channel_test.go @@ -0,0 +1,27 @@ +// Copyright 2019 Yegor Myskin. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package tailor + +import ( + "testing" + "time" +) + +func TestChannelBasedRateLimiterDisallow(t *testing.T) { + l := NewChannelBasedRateLimiter(30) + defer l.Close() + + start := time.Now() + for i := 0; i < 100; i++ { + if !l.Allow() { + t.FailNow() + } + } + dur := time.Since(start) + + if dur < 3333*time.Millisecond || dur > 3500*time.Millisecond { + t.Errorf("expected duration: ~3.33s, actual: %s", dur) + } +} diff --git a/seeker_test.go b/seeker_test.go index aeb31b4..27a7048 100644 --- a/seeker_test.go +++ b/seeker_test.go @@ -1,3 +1,7 @@ +// Copyright 2019 Yegor Myskin. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package tailor import (