From 42100bf0069c0b916cf6aa86016965a8bf2acd06 Mon Sep 17 00:00:00 2001 From: Christopher Moussa Date: Fri, 11 Feb 2022 09:06:34 -0800 Subject: [PATCH] t: add queue priority sharness tests --- t/Makefile.am | 3 +- t/t1012-mf-priority-queues.t | 113 +++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100755 t/t1012-mf-priority-queues.t diff --git a/t/Makefile.am b/t/Makefile.am index 4ca44b8be..9f33c9b0c 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -12,7 +12,8 @@ TESTSCRIPTS = \ t1008-mf-priority-update.t \ t1009-pop-db.t \ t1010-update-usage.t \ - t1011-job-archive-interface.t + t1011-job-archive-interface.t \ + t1012-mf-priority-queues.t dist_check_SCRIPTS = \ $(TESTSCRIPTS) \ diff --git a/t/t1012-mf-priority-queues.t b/t/t1012-mf-priority-queues.t new file mode 100755 index 000000000..e28f62866 --- /dev/null +++ b/t/t1012-mf-priority-queues.t @@ -0,0 +1,113 @@ +#!/bin/bash + +test_description='Test multi-factor priority plugin queue support with a single user' + +. `dirname $0`/sharness.sh +MULTI_FACTOR_PRIORITY=${FLUX_BUILD_DIR}/src/plugins/.libs/mf_priority.so +SUBMIT_AS=${SHARNESS_TEST_SRCDIR}/scripts/submit_as.py +DB_PATH=$(pwd)/FluxAccountingTest.db + +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 'check that mf_priority plugin is loaded' ' + flux jobtap list | grep mf_priority +' + +test_expect_success 'create flux-accounting DB' ' + flux account -p $(pwd)/FluxAccountingTest.db create-db +' + +test_expect_success 'add some banks to the DB' ' + flux account -p ${DB_PATH} add-bank root 1 && + flux account -p ${DB_PATH} add-bank --parent-bank=root account1 1 && + flux account -p ${DB_PATH} add-bank --parent-bank=root account2 1 +' + +test_expect_success 'add some queues to the DB' ' + flux account -p ${DB_PATH} add-queue standby --priority=-1000 && + flux account -p ${DB_PATH} add-queue expedite --priority=10000 && + flux account -p ${DB_PATH} add-queue bronze --priority=200 && + flux account -p ${DB_PATH} add-queue silver --priority=300 && + flux account -p ${DB_PATH} add-queue gold --priority=400 +' + +test_expect_success 'add a user to the DB' ' + flux account -p ${DB_PATH} add-user --username=user5011 \ + --userid=5011 --bank=account1 --queues="standby,bronze,silver,gold,expedite" && + flux account -p ${DB_PATH} add-user --username=user5011 \ + --userid=5011 --bank=account2 --queues="standby" +' + +test_expect_success 'view user information' ' + flux account -p ${DB_PATH} view-user user5011 +' + +test_expect_success 'send the user information to the plugin' ' + flux account-priority-update -p $(pwd)/FluxAccountingTest.db +' + +test_expect_success 'stop the queue' ' + flux queue stop +' + +test_expect_success 'submit a job using a queue the user does not belong to' ' + test_must_fail flux python ${SUBMIT_AS} 5011 --setattr=system.bank=account2 \ + --setattr=system.queue=expedite -n1 hostname > unavail_queue.out 2>&1 && + test_debug "unavail_queue.out" && + grep "Queue not valid for user" unavail_queue.out +' + +test_expect_success 'submit a job using a nonexistent queue' ' + test_must_fail flux python ${SUBMIT_AS} 5011 --setattr=system.queue=foo \ + -n1 hostname > bad_queue.out 2>&1 && + test_debug "bad_queue.out" && + grep "Queue does not exist" bad_queue.out +' + +test_expect_success 'submit a job using standby queue, which should decrease job priority' ' + jobid1=$(flux python ${SUBMIT_AS} 5011 --job-name=standby \ + --setattr=system.bank=account1 --setattr=system.queue=standby -n1 hostname) && + flux job wait-event -f json $jobid1 priority | jq '.context.priority' > job1.test && + cat <<-EOF >job1.expected && + 0 + EOF + test_cmp job1.expected job1.test +' + +test_expect_success 'submit a job using expedite queue, which should increase priority' ' + jobid2=$(flux python ${SUBMIT_AS} 5011 --job-name=expedite \ + --setattr=system.bank=account1 --setattr=system.queue=expedite -n1 hostname) && + flux job wait-event -f json $jobid2 priority | jq '.context.priority' > job2.test && + cat <<-EOF >job2.expected && + 100050000 + EOF + test_cmp job2.expected job2.test +' + +test_expect_success 'submit a job using the rest of the available queues' ' + flux python ${SUBMIT_AS} 5011 --job-name=bronze --setattr=system.queue=bronze -n1 hostname && + flux python ${SUBMIT_AS} 5011 --job-name=silver --setattr=system.queue=silver -n1 hostname && + flux python ${SUBMIT_AS} 5011 --job-name=gold --setattr=system.queue=gold -n1 hostname +' + +test_expect_success 'check order of job queue' ' + flux jobs -A --suppress-header --format={name} > multi_queues.test && + cat <<-EOF >multi_queues.expected && + expedite + gold + silver + bronze + standby + EOF + test_cmp multi_queues.expected multi_queues.test +' + +test_done