Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
756ef0e3
Commit
756ef0e3
authored
Dec 14, 2018
by
Jeremy Morrell
Committed by
Jeremy Morrell
Dec 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some deficiencies in the monitor function
parent
b2e292c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
2 deletions
+46
-2
monitor.sh
lib/monitor.sh
+3
-2
stdlib.sh
test/mocks/stdlib.sh
+13
-0
unit
test/unit
+30
-0
No files found.
lib/monitor.sh
View file @
756ef0e3
...
...
@@ -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
)
"
...
...
test/mocks/stdlib.sh
0 → 100644
View file @
756ef0e3
# mock these functions from the stdlib
nowms
()
{
:
}
mtime
()
{
:
}
mmeasure
()
{
:
}
test/unit
View file @
756ef0e3
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment