Skip to content

Commit

Permalink
planner_multi: add unit tests for partial cancel
Browse files Browse the repository at this point in the history
Problem: there are no unit tests for planner_multi partial cancel.

Add tests to ensure consistency and that a sequence of partial cancels
that remove all job resources is identical to a full cancel. Also
ensure resource permutations and zero spans are handled correctly.
  • Loading branch information
milroy committed Jul 9, 2024
1 parent fb00e95 commit 2d8b7b1
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion resource/planner/test/planner_test02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,112 @@ static int test_multi_update ()

}

static int test_partial_cancel ()
{
bool bo = false, removed = false, removed1 = false, removed2 = false,
removed3 = false, removed4 = false;
size_t len = 5;
int rc = -1;
int64_t span1 = -1, span2 = -1, span3 = -1, span4 = -1, avail1 = -1,
avail2 = -1, avail3 = -1, avail4 = -1, avail5 = -1, avail6 = -1,
avail7 = -1;
const uint64_t resource_totals[] = {10, 20, 30, 40, 50};
const char *resource_types[] = {"A", "B", "C", "D", "E"};
const char *resource_types1[] = {"B", "A", "E"};
const char *resource_types2[] = {"B", "A", "C", "D", "G", "X", "Y"};
const char *resource_types3[] = {"C", "D", "A", "B", "E"};
const char *resource_types4[] = {"D"};
const char *resource_types5[] = {"A"};
const char *resource_types6[] = {"B"};
const uint64_t reduce1[] = {1, 0, 0, 0, 0};
const uint64_t reduce2[] = {2, 1, 5};
const uint64_t reduce3[] = {2, 1, 5, 6, 7, 8, 9};
const uint64_t reduce4[] = {3, 3, 0, 0, 0};
const uint64_t reduce5[] = {1};
const uint64_t request1[] = {2, 0, 0, 0, 0};
const uint64_t request2[] = {1, 2, 3, 4, 5};
const uint64_t request3[] = {2, 2, 0, 0, 0};
planner_multi_t *ctx = NULL;

ctx = planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len);

span1 = planner_multi_add_span (ctx, 0, 1000, request1, len);
span2 = planner_multi_add_span (ctx, 0, 2000, request2, len);
rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types,
5, removed);
avail1 = planner_multi_avail_resources_at (ctx, 0, 0);
bo = (bo || avail1 != 8 || removed || rc != 0);
ok (!bo, "reducing span results in expected availability counts and doesn't remove span");

removed = false;
rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types,
5, removed);
avail1 = planner_multi_avail_resources_at (ctx, 0, 0);
bo = (bo || avail1 != 9 || !removed || rc != 0);
ok (!bo, "two partial reductions with appropriate removals totally remove span");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce2, resource_types1,
3, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 1);
bo = (bo || avail2 != 20 || removed || rc != 0);
ok (!bo, "underspecified and reordered reduction types is handled correctly");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce3, resource_types2,
7, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 2);
bo = (bo || avail2 != 27 || removed || rc != -1);
ok (!bo, "incorrect resource type reduction does not change availability");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce4, resource_types3,
5, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 3);
bo = (bo || avail2 != 39 || removed || rc != 0);
ok (!bo, "reordered partial reduction results in correct availability");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce5, resource_types4,
1, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 3);
bo = (bo || avail2 != 40 || !removed || rc != 0);
ok (!bo, "removing final span resource completely removes span");

span3 = planner_multi_add_span (ctx, 0, 2000, resource_totals, len);
avail1 = planner_multi_avail_resources_at (ctx, 1000, 0);
avail2 = planner_multi_avail_resources_at (ctx, 1000, 1);
avail3 = planner_multi_avail_resources_at (ctx, 1000, 2);
avail4 = planner_multi_avail_resources_at (ctx, 1000, 3);
avail5 = planner_multi_avail_resources_at (ctx, 1000, 4);
bo = (bo || avail1 != 0 || avail2 != 0 || avail3 != 0 || avail4 != 0
|| avail5 != 0 || !removed || rc != 0);
ok (!bo, "can fully allocate resources after partial removals");

span4 = planner_multi_add_span (ctx, 3000, 1000, request3, len);
rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5,
1, removed1);
rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5,
1, removed2);
rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6,
1, removed3);
rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6,
1, removed4);
avail6 = planner_multi_avail_resources_at (ctx, 3500, 0);
avail7 = planner_multi_avail_resources_at (ctx, 3500, 1);
bo = (bo || avail6 != 10 || avail7 != 20 || removed1 || removed2
|| removed3 || !removed4 || rc != 0);
ok (!bo, "series of partial removals fully removes span");

planner_multi_destroy (&ctx);

return 0;

}

int main (int argc, char *argv[])
{
plan (98);
plan (106);

test_multi_basics ();

Expand All @@ -719,6 +822,8 @@ int main (int argc, char *argv[])

test_multi_update ();

test_partial_cancel ();

done_testing ();

return EXIT_SUCCESS;
Expand Down

0 comments on commit 2d8b7b1

Please sign in to comment.