github.com/blend/go-sdk@v1.20220411.3/ratelimiter/wait_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package ratelimiter 9 10 import ( 11 "testing" 12 "time" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func Test_Wait_Calculate(t *testing.T) { 18 its := assert.New(t) 19 20 wait := Wait{2 * 1024, time.Second}.Calculate( 21 4*1024, 22 time.Second, 23 ) 24 its.Equal(time.Second, wait) 25 26 wait = Wait{4 * 1024, time.Second}.Calculate(2*1024, time.Second) 27 its.Equal(-500*time.Millisecond, wait) 28 29 // originally 4 kilobytes a second 30 // or 240 kilobytes in a minute (i.e 60 seconds, or 60 * 4) 31 wait = Wait{2 * 1024, time.Second}.Calculate(240*1024, time.Minute) 32 its.Equal(time.Minute, wait, "THINK ABOUT IT. HOW MANY MINUTES PRODUCED 240kb") 33 34 wait = Wait{2 * 1024, time.Second}.Calculate(3*1024, time.Second) 35 its.Equal(500*time.Millisecond, wait) 36 }