]> git.hungrycats.org Git - bees/commitdiff
test: cover ceil(), bees_parse_size_double(), and the thread-max shape
authorZygo Blaxell <bees@furryterror.org>
Mon, 31 Aug 2026 00:43:35 +0000 (20:43 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
Add expect_size()/expect_size_double() helpers to config-parse and
exercise the size-expression grammar, which was previously untested here.
Cover the ceil() function (rounding up, one-argument arity, missing-paren
rejection), the default thread-max shape max(1, ceil(...)), and the double
variant that loadavg-target relies on -- including the contrast that the
integer bees_parse_size() truncates "0.5" to 0 while
bees_parse_size_double() preserves it.  The ${...} substitutions need a
live filesystem and are left to the integration tests; these cases use
literal operands.

Assisted-by: Claude-Code:claude-opus-4-8
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
test/config-parse.cc

index d849023285c5dba6bd6ca9ce0cd30fa688af4772..5ad3e1a473c1fa4f084d0d6c80fbd558eccb759e 100644 (file)
@@ -28,6 +28,20 @@ expect_duration(const string &s, double expected)
        THROW_CHECK3(runtime_error, s, actual, expected, fabs(actual - expected) < 0.001);
 }
 
+static void
+expect_size(const string &s, uint64_t expected)
+{
+       const auto actual = bees_parse_size(s);
+       THROW_CHECK3(runtime_error, s, actual, expected, actual == expected);
+}
+
+static void
+expect_size_double(const string &s, double expected)
+{
+       const auto actual = bees_parse_size_double(s);
+       THROW_CHECK3(runtime_error, s, actual, expected, fabs(actual - expected) < 0.001);
+}
+
 int
 main()
 {
@@ -50,5 +64,27 @@ main()
        expect_invalid([]() { bees_parse_duration("1.2.3s"); });
        expect_invalid([]() { bees_parse_duration("1s junk"); });
 
+       // Size expressions: existing grammar still works.
+       expect_size("128K", uint64_t(128) << 10);
+       expect_size("min(4, 8)", 4);
+       expect_size("max(4, 8)", 8);
+
+       // ceil() rounds up; the default thread-max shape evaluates as expected.
+       expect_size("ceil(7.5)", 8);
+       expect_size("ceil(8)", 8);
+       expect_size("ceil(8 * 1.5)", 12);
+       expect_size("ceil(5 * 1.5)", 8);                // 7.5 -> 8 (truncation would give 7)
+       expect_size("max(1, ceil(2 * 1.0))", 2);        // default thread-max shape
+       expect_size("min(4, ceil(8 * 1.0))", 4);        // min()+ceil() composition
+
+       expect_invalid([]() { bees_parse_size("ceil(8"); });     // missing ')'
+       expect_invalid([]() { bees_parse_size("ceil(8, 9)"); }); // ceil takes one arg
+
+       // The double variant keeps fractional results (loadavg-target relies on
+       // this; bees_parse_size would truncate 0.5 -> 0 = "throttling disabled").
+       expect_size_double("0.5", 0.5);
+       expect_size_double("8 / 2", 4.0);
+       expect_size("0.5", 0);                          // integer variant truncates
+
        return 0;
 }