diff --git a/t/t1001-mf-priority.t b/t/t1001-mf-priority.t new file mode 100755 index 000000000..0f184245a --- /dev/null +++ b/t/t1001-mf-priority.t @@ -0,0 +1,84 @@ +#!/bin/bash + +test_description='Test multi-factor priority plugin' + +. `dirname $0`/sharness.sh +MULTI_FACTOR_PRIORITY=${FLUX_BUILD_DIR}/src/plugins/.libs/mf_priority.so +# BULK_UPDATE=${FLUX_BUILD_DIR}/t/scripts/send_fake_payloads.py + +export TEST_UNDER_FLUX_NO_JOB_EXEC=y +export TEST_UNDER_FLUX_SCHED_SIMPLE_MODE="limited=1" +test_under_flux 1 job + +flux setattr log-stderr-level 1 + +test_expect_success 'load multi-factor priority plugin' ' + flux jobtap load -r .priority-default ${MULTI_FACTOR_PRIORITY} +' + +test_expect_success 'list all loaded plugins' ' + flux jobtap list -a > test.txt +' + +test_expect_success 'make sure multi-factor priority plugin is loaded' ' + test_cmp test.txt ${FLUX_BUILD_DIR}/t/expected/loaded_priority.txt +' + +test_expect_success 'create fake_payload.py' ' +cat <<-EOF >fake_payload.py +import flux +import pwd +import getpass + +username = getpass.getuser() +userid = pwd.getpwnam(username).pw_uid +# tell plugin to clear multimap for new update +flux.Flux().rpc("job-manager.mf_priority.clear_map", {}).get() +# create a JSON payload with the results of the query +data = {"userid": str(userid), "bank": "account3", "fairshare": "0.45321"} +flux.Flux().rpc("job-manager.mf_priority.rec_update", data).get() +data = {"userid": str(userid), "bank": "account2", "fairshare": "0.11345"} +flux.Flux().rpc("job-manager.mf_priority.rec_update", data).get() +EOF +' + +test_expect_success 'update plugin with sample test data' ' + flux python fake_payload.py +' + +test_expect_success 'submit a job with default urgency' ' + jobid=$(flux mini submit --setattr=system.bank=account3 -n1 hostname) && + flux job wait-event -f json $jobid priority | jq '.context.priority' > test_job1.txt && + test_cmp test_job1.txt ${FLUX_BUILD_DIR}/t/expected/job_1_priority.txt +' + +test_expect_success 'submit a job with custom urgency' ' + jobid=$(flux mini submit --setattr=system.bank=account3 --urgency=15 -n1 hostname) && + flux job wait-event -f json $jobid priority | jq '.context.priority' > test_job2.txt && + test_cmp test_job2.txt ${FLUX_BUILD_DIR}/t/expected/job_2_priority.txt +' + +test_expect_success 'submit a job with urgency of 0' ' + jobid=$(flux mini submit --setattr=system.bank=account3 --urgency=0 -n1 hostname) && + flux job wait-event -f json $jobid priority | jq '.context.priority' > test_job3.txt && + test_cmp test_job3.txt ${FLUX_BUILD_DIR}/t/expected/job_3_priority.txt && + flux job cancel $jobid +' + +test_expect_success 'submit a job with urgency of 31' ' + jobid=$(flux mini submit --setattr=system.bank=account3 --urgency=31 -n1 hostname) && + flux job wait-event -f json $jobid priority | jq '.context.priority' > test_job4.txt && + test_cmp test_job4.txt ${FLUX_BUILD_DIR}/t/expected/job_4_priority.txt +' + +test_expect_success 'submit a job with other bank' ' + jobid=$(flux mini submit --setattr=system.bank=account2 -n1 hostname) && + flux job wait-event -f json $jobid priority | jq '.context.priority' > test_job5.txt && + test_cmp test_job5.txt ${FLUX_BUILD_DIR}/t/expected/job_5_priority.txt +' + +test_expect_success 'submitting a job without specifying a bank while belonging to more than one bank fails' ' + test_must_fail flux mini submit -n1 hostname +' + +test_done