Skip to content

Commit 01eecd7

Browse files
committed
tests: internal: Add test cases for adaptive flushing
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 8a3138f commit 01eecd7

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

tests/internal/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ set(UNIT_TESTS_FILES
5757
unicode.c
5858
opentelemetry.c
5959
storage_dlq.c
60+
engine_adaptive_flush.c
6061
)
6162

6263
# TLS helpers
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
#include <fluent-bit/flb_config.h>
4+
#include <fluent-bit/flb_engine.h>
5+
#include "flb_tests_internal.h"
6+
7+
static void test_target_level_thresholds()
8+
{
9+
struct flb_config *config;
10+
11+
config = flb_config_init();
12+
TEST_CHECK(config != NULL);
13+
14+
config->flush_adaptive_low_pressure = 25.0;
15+
config->flush_adaptive_medium_pressure = 50.0;
16+
config->flush_adaptive_high_pressure = 75.0;
17+
18+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 0.0) == 0);
19+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 25.0) == 0);
20+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 25.1) == 1);
21+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 49.9) == 1);
22+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 50.0) == 2);
23+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 74.9) == 2);
24+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 75.0) == 3);
25+
TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 100.0) == 3);
26+
27+
flb_config_exit(config);
28+
}
29+
30+
static void test_interval_levels_and_bounds()
31+
{
32+
struct flb_config *config;
33+
34+
config = flb_config_init();
35+
TEST_CHECK(config != NULL);
36+
37+
config->flush = 1.0;
38+
config->flush_adaptive_min_interval = 0.5;
39+
config->flush_adaptive_max_interval = 2.0;
40+
41+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 0) == 2.0);
42+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 1) == 1.0);
43+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 2) == 0.75);
44+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 0.5);
45+
46+
/* clamp low/high out-of-range levels */
47+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, -1) == 2.0);
48+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 9) == 0.5);
49+
50+
/* clamp by min/max bounds */
51+
config->flush = 10.0;
52+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 2.0);
53+
54+
config->flush = 0.1;
55+
TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 0.5);
56+
57+
flb_config_exit(config);
58+
}
59+
60+
TEST_LIST = {
61+
{ "target_level_thresholds", test_target_level_thresholds },
62+
{ "interval_levels_and_bounds", test_interval_levels_and_bounds },
63+
{ 0 }
64+
};

0 commit comments

Comments
 (0)