skip to content
==> tests/weights.c <==
1/* Weights::from_keys: defaults, overrides, the floor on tick_ms, errors in the Rust's words. */
2#include "mesh/check.h"
3#include "mesh/sched_weights.h"
4
5#include <stdlib.h>
6
7int main(void) {
8    ms_map m = {0};
9    msw_weights w;
10    char *err = NULL;
11    CHECK(msw_from_keys(&m, &w, &err));
12    msw_weights d = msw_default();
13    CHECK(msw_eq(&w, &d));
14    ms_set(&m, "sched_hold_ms", "2000", true);
15    ms_set(&m, "sched_improve", "0.5", true);
16    ms_set(&m, "sched_tick_ms", "10", true);
17    ms_set(&m, "sched_owner_share", "0.4", true);
18    CHECK(msw_from_keys(&m, &w, &err));
19    CHECK(w.hold_ms == 2000 && w.improve == 0.5 && w.tick_ms == 100 && w.owner_share == 0.4f && w.dwell_ms == 60000);
20    ms_set(&m, "sched_hold_ms", "x", true);
21    CHECK(!msw_from_keys(&m, &w, &err));
22    CHECK_S(err, "cluster: sched_hold_ms = \"x\": an integer");
23    free(err);
24    ms_set(&m, "sched_hold_ms", "1", true);
25    ms_set(&m, "sched_reserve", "1", true);
26    CHECK(!msw_from_keys(&m, &w, &err));
27    CHECK_S(err, "cluster: sched_improve 0..10, sched_reserve 0..1");
28    free(err);
29    ms_set(&m, "sched_reserve", "nope", true);
30    CHECK(!msw_from_keys(&m, &w, &err));
31    CHECK_S(err, "cluster: sched_reserve = \"nope\": a number");
32    free(err);
33    ms_free(&m);
34    return mesh_check_done();
35}