|
|
@ -7,6 +7,8 @@ |
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define __STDC_FORMAT_MACROS |
|
|
|
|
|
|
|
#include <inttypes.h> |
|
|
|
#include <limits> |
|
|
|
#include <limits> |
|
|
|
#include "util/testharness.h" |
|
|
|
#include "util/testharness.h" |
|
|
|
#include "util/rate_limiter.h" |
|
|
|
#include "util/rate_limiter.h" |
|
|
@ -63,10 +65,10 @@ TEST(RateLimiterTest, Rate) { |
|
|
|
auto elapsed = env->NowMicros() - start; |
|
|
|
auto elapsed = env->NowMicros() - start; |
|
|
|
double rate = arg.limiter->GetTotalBytesThrough() |
|
|
|
double rate = arg.limiter->GetTotalBytesThrough() |
|
|
|
* 1000000.0 / elapsed; |
|
|
|
* 1000000.0 / elapsed; |
|
|
|
fprintf(stderr, "request size [1 - %ld], limit %ld KB/sec, " |
|
|
|
fprintf(stderr, "request size [1 - %" PRIi64 "], limit %" PRIi64 |
|
|
|
"actual rate: %lf KB/sec, elapsed %.2lf seconds\n", |
|
|
|
" KB/sec, actual rate: %lf KB/sec, elapsed %.2lf seconds\n", |
|
|
|
arg.request_size - 1, target / 1024, rate / 1024, |
|
|
|
arg.request_size - 1, target / 1024, rate / 1024, |
|
|
|
elapsed / 1000000.0); |
|
|
|
elapsed / 1000000.0); |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_GE(rate / target, 0.95); |
|
|
|
ASSERT_GE(rate / target, 0.95); |
|
|
|
ASSERT_LE(rate / target, 1.05); |
|
|
|
ASSERT_LE(rate / target, 1.05); |
|
|
|