Commit 756ef0e3 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by Jeremy Morrell

Fix some deficiencies in the monitor function

parent b2e292c6
......@@ -45,12 +45,13 @@ monitor_memory_usage() {
monitor() {
local command_name=$1
shift
local command="${@:-}"
local command=( "$@" )
local peak_mem_output=$(mktemp)
local start=$(nowms)
# execute the subcommand and save the peak memory usage
monitor_memory_usage $peak_mem_output $command
monitor_memory_usage $peak_mem_output "${command[@]}"
mtime "exec.$command_name.time" "${start}"
mmeasure "exec.$command_name.memory" "$(cat $peak_mem_output)"
......
# mock these functions from the stdlib
nowms() {
:
}
mtime() {
:
}
mmeasure() {
:
}
......@@ -19,6 +19,10 @@ print_args() {
done
}
print_number_args() {
echo "$#"
}
testMonitorMemory() {
local mem_output=$(mktemp)
local stdout_capture=$(mktemp)
......@@ -36,6 +40,29 @@ testMonitorMemory() {
assertEquals "second line" "--bar=baz lol hi" "$(tail -n 1 $stdout_capture)"
}
testMonitor() {
local out
# test that we're forwarding empty arguments correctly
out=$(monitor "command-name" print_number_args "" "" "" "")
assertEquals "4" "$out"
# Don't expand *
out=$(monitor "command-name" echo "*")
assertEquals "*" "$out"
out=$(monitor "command-name" print_number_args "*")
assertEquals "1" "$out"
# # Don't split arguments with a space
out=$(monitor "command-name" echo "1 3")
assertEquals "1 3" "$out"
# # Test everything with an empty arg
out=$(monitor "command-name" echo 1 "" 2 "3 4" "*")
assertEquals "1 2 3 4 *" "$out"
}
testOutput() {
local stdout
......@@ -111,6 +138,9 @@ testKeyValueNoFile() {
assertEquals "$(kv_list $space)" ""
}
# mocks
source "$(pwd)"/test/mocks/stdlib.sh
# the modules to be tested
source "$(pwd)"/lib/monitor.sh
source "$(pwd)"/lib/output.sh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment