Skip to content

Commit

Permalink
Merge pull request #1175 from grondo/test_under_flux
Browse files Browse the repository at this point in the history
sharness: test_under_flux: add fatal error if modules loaded during test aren't unloaded at test completion
  • Loading branch information
garlick authored Aug 31, 2017
2 parents 2eb43ea + 9ede5d6 commit e255d0f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions t/sharness.d/flux-sharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ test_size_large() {
echo ${size}
}


#
# Tests using test_under_flux() and which load their own modules should
# ensure those modules are unloaded at the end of the test for proper
# cleanup and test coverage (also as a general principle, module unload
# should be something explicitly tested).
#
# The functions below ensure that every module loaded at "test_done" time
# when test_under_flux() was used was also loaded before test_under_flux
# was called.
#
flux_module_list() {
flux module list | awk '!/^Module/{print $1}' | sort
}

check_module_list() {
flux_module_list > module-list.final
while read module; do
grep "^$module$" module-list.initial >/dev/null 2>&1 \
|| bad="${bad}${bad:+ }$module"
done < module-list.final
if test -n "$bad"; then
test -n "$logfile" \
&& say_color error >&3 \
"Error: manually loaded module(s) not unloaded: $bad"
# This function is run under test_eval_ so redirect
# error message to &5 (saved stdout) so text doesn't disappear:
error >&5 2>&1 "manually loaded module(s) not unloaded: $bad"
fi
}

#
# Reinvoke a test file under a flux comms instance
#
Expand All @@ -35,6 +66,8 @@ test_under_flux() {
log_file="$TEST_NAME.broker.log"
if test -n "$TEST_UNDER_FLUX_ACTIVE" ; then
cleanup rm "${SHARNESS_TEST_DIRECTORY:-..}/$log_file"
flux_module_list > module-list.initial
cleanup check_module_list
return
fi
quiet="-o -q,-Slog-filename=${log_file},-Slog-forward-level=7"
Expand Down
29 changes: 29 additions & 0 deletions t/t0001-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ test_expect_success 'test_under_flux works' '
) &&
grep "size=2" test-under-flux/out
'

test_expect_success 'test_under_flux fails if loaded modules are not unloaded' '
mkdir -p test-under-flux && (
cd test-under-flux &&
cat >.test.modcheck.t <<-EOF &&
#!/bin/sh
test_description="test_under_flux with module loaded, but not unloaded"
. "\$SHARNESS_TEST_SRCDIR"/sharness.sh
test_under_flux 2 minimal
test_expect_success "flux module load kvs" "
flux module load -r 0 kvs
"
test_done
EOF
chmod +x .test.modcheck.t &&
SHARNESS_TEST_DIRECTORY=`pwd` &&
export SHARNESS_TEST_SRCDIR SHARNESS_TEST_DIRECTORY FLUX_BUILD_DIR debug &&
test_expect_code 1 ./.test.modcheck.t 2>err.modcheck \
| grep -v sharness: >out.modcheck
) &&
cat >expected.modcheck <<-EOF &&
ok 1 - flux module load kvs
# passed all 1 test(s)
1..1
error: manually loaded module(s) not unloaded: kvs
EOF
test_cmp expected.modcheck test-under-flux/out.modcheck
'

test_expect_success 'flux-start -o,--setattr ATTR=VAL can set broker attributes' '
ATTR_VAL=`flux start ${ARGS} -o,--setattr=foo-test=42 flux getattr foo-test` &&
test $ATTR_VAL -eq 42
Expand Down

0 comments on commit e255d0f

Please sign in to comment.