Skip to content

Commit 2ed7bfd

Browse files
author
Alan Christie
committed
- PipelineTester now supports validation of metrics
1 parent f25ef97 commit 2ed7bfd

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/groovy/PipelineTester.groovy

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Tester {
5757
String testSearchDir = '../../..'
5858
String sdExt = '.dsd.json'
5959
String optionPrefix = 'arg.'
60+
String metricsFile = 'output_metrics.txt'
6061
String outputBasePath = System.getProperty('user.dir') + '/tmp/PipelineTester'
6162
String outputRegex = '-o (\\S+)'
6263
String infoPrompt = '->'
@@ -549,7 +550,7 @@ class Tester {
549550
def paramsBlock = section.value['params']
550551
def seeBlock = section.value['see']
551552
def createsBlock = section.value['creates']
552-
def doesNotCreateBlock = section.value['does_not_create']
553+
def metricsBlock = section.value['metrics']
553554

554555
// Enforce conditions on block combinations...
555556
if (command != null && paramsBlock != null) {
@@ -696,6 +697,38 @@ class Tester {
696697

697698
}
698699

700+
// Has the user specified any metrics?
701+
// These are located in the `output_metrics.txt` file.
702+
if (validated && metricsBlock != null) {
703+
// A metrics file must exist.
704+
Properties properties = new Properties()
705+
String metricsPath = testOutputPath.toString() + File.separator + metricsFile
706+
File propertiesFile = new File(metricsPath)
707+
if (propertiesFile.exists()) {
708+
propertiesFile.withInputStream {
709+
properties.load(it)
710+
}
711+
metricsBlock.each { metric ->
712+
String fileProperty = properties."$metric.key"
713+
if (fileProperty == null) {
714+
// The Metric is not in the file!
715+
err("Metric for '$metric.key' is not in the metrics file")
716+
validated = false
717+
} else {
718+
def finder = (fileProperty =~ /${metric.value}/)
719+
if (finder.count == 0) {
720+
err("Expected value for metric '$metric.key' ($metric.value)" +
721+
" does not match file value ($fileProperty)")
722+
validated = false
723+
}
724+
}
725+
}
726+
} else {
727+
err("Expected metrics but there was no metrics file ($metricsFile)")
728+
validated = false
729+
}
730+
}
731+
699732
} else {
700733
err("Pipeline exitValue=$exitValue. <stderr> follows...")
701734
}

src/groovy/pipeline.test.template

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@
109109
// and 'output.png' but an 'output.txt' is also expected as that's
110110
// defined in the 'setup_collection' section (above).
111111

112-
creates: [ 'output.png' ]
112+
creates: [ 'output.png' ],
113+
114+
// Metrics.
115+
//
116+
// If your pipeline creates standard metrics - a Java properties file
117+
// with the name 'output_metrics.txt' you can use the metrics block
118+
// here to check the generated values. You can specify a property
119+
// (a key) and a regular expression string value.
120+
121+
metrics: [ __StatusMessage__: 'kel: 0.171, t1/2: 4.06, V: 7.07, CL: 20.1' ]
113122

114123
],
115124

0 commit comments

Comments
 (0)