Skip to content

Commit

Permalink
t: add tests for updating both queue and bank
Browse files Browse the repository at this point in the history
Problem: flux-accounting has no tests for updating both the queue and
the bank of a job at the same time.

Add a new test file which tests updating both the queue and the bank at
the same time as well as some combinations where at least one attribute
update is expected to fail (i.e an invalid bank or an invalid queue).

In both of the cases where at least one attribute fails, the entire
request will fail and the job will remain under its original attributes.
  • Loading branch information
cmoussa1 committed Mar 14, 2024
1 parent 253ad5c commit 2621f14
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TESTSCRIPTS = \
t1030-mf-priority-update-queue.t \
t1031-mf-priority-issue406.t \
t1032-mf-priority-update-bank.t \
t1033-mf-priority-update-job.t \
t5000-valgrind.t \
python/t1000-example.py

Expand Down
117 changes: 117 additions & 0 deletions t/t1033-mf-priority-update-job.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

test_description='test updating a combination of queue and bank for a pending job in priority plugin'

. `dirname $0`/sharness.sh

mkdir -p conf.d

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 -o,--config-path=$(pwd)/conf.d

flux setattr log-stderr-level 1

test_expect_success 'create flux-accounting DB' '
flux account -p $(pwd)/FluxAccountingTest.db create-db
'

test_expect_success 'start flux-accounting service' '
flux account-service -p ${DB_PATH} -t
'

test_expect_success 'load multi-factor priority plugin' '
flux jobtap load -r .priority-default ${MULTI_FACTOR_PRIORITY} &&
flux jobtap list | grep mf_priority
'

test_expect_success 'add some banks to the DB' '
flux account add-bank root 1 &&
flux account add-bank --parent-bank=root A 1 &&
flux account add-bank --parent-bank=root B 1
'

test_expect_success 'add some queues to the DB' '
flux account add-queue bronze --priority=100 &&
flux account add-queue silver --priority=200 &&
flux account add-queue gold --priority=300
'

test_expect_success 'add a user to the DB' '
flux account add-user --username=user5001 \
--userid=5001 \
--bank=A \
--queues="bronze,silver" &&
flux account add-user --username=user5001 \
--userid=5001 \
--bank=B \
--queues="bronze,silver"
'

test_expect_success 'send flux-accounting DB information to the plugin' '
flux account-priority-update -p $(pwd)/FluxAccountingTest.db
'

test_expect_success 'configure flux with some queues' '
cat >conf.d/queues.toml <<-EOT &&
[queues.bronze]
[queues.silver]
[queues.gold]
EOT
flux config reload
'

test_expect_success 'submit job for testing' '
jobid=$(flux python ${SUBMIT_AS} 5001 --queue=bronze sleep 30) &&
flux job wait-event -f json $jobid priority &&
flux job eventlog $jobid > eventlog.out &&
grep "1050000" eventlog.out
'

test_expect_success 'update both queue and bank successfully' '
flux update $jobid queue=silver bank=B &&
flux job wait-event -f json $jobid priority &&
flux job eventlog $jobid > eventlog.out &&
grep "attributes.system.queue=\"silver\"" eventlog.out &&
grep 2050000 eventlog.out &&
grep "attributes.system.bank=\"B\"" eventlog.out &&
flux job cancel $jobid
'

test_expect_success 'submit another job for testing' '
jobid=$(flux python ${SUBMIT_AS} 5001 --queue=bronze sleep 30) &&
flux job wait-event -f json $jobid priority
'

test_expect_success 'update job with invalid combination (invalid bank)' '
test_must_fail flux update $jobid queue=silver bank=foo > nonexistent_bank.out 2>&1 &&
test_debug "cat nonexistent_bank.out" &&
grep "cannot find user/bank or user/default bank entry for uid:" nonexistent_bank.out
'

test_expect_success 'check that job is still in original queue' '
flux job info $jobid jobspec > jobspec.out &&
grep "\"queue\": \"bronze\"" jobspec.out
'

test_expect_success 'update job with invalud combination (invalid queue)' '
test_must_fail flux update $jobid bank=B queue=gold > unavail_queue.out 2>&1 &&
test_debug "cat unavail_queue.out" &&
grep "ERROR: mf_priority: queue not valid for user: gold" unavail_queue.out
'

test_expect_success 'check that job is still under original bank' '
flux job eventlog $jobid > eventlog.out &&
grep "attributes.system.bank=\"A\"" eventlog.out &&
flux job cancel $jobid
'

test_expect_success 'shut down flux-accounting service' '
flux python -c "import flux; flux.Flux().rpc(\"accounting.shutdown_service\").get()"
'

test_done

0 comments on commit 2621f14

Please sign in to comment.