// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $actualData = 2.0; $expectedData1 = 1; assertsDouble($actualData)->isGreaterThan($expectedData1); // and these should fail try { $expectedData2 = 2; assertsDouble($actualData)->isGreaterThan($expectedData2); } catch (Exception $e) { $checkpoint->test2Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Passed"); assertsBoolean($checkpoint->test2Passed)->isTrue(); });
} try { $intData = 11; assertsDouble($intData)->isDouble(); } catch (Exception $e) { $checkpoint->intTest2Passed = true; } try { $objectData = new stdClass(); assertsDouble($objectData)->isDouble(); } catch (Exception $e) { $checkpoint->objectTestPassed = true; } try { $stringData = ""; assertsDouble($stringData)->isDouble(); } catch (Exception $e) { $checkpoint->stringTestPassed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("nullTestPassed"); assertsBoolean($checkpoint->nullTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("arrayTestPassed"); assertsBoolean($checkpoint->arrayTestPassed)->isTrue();
// // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // these should pass $actualData = 2.0; $expectedData1 = 3; assertsDouble($actualData)->isLessThanOrEqualTo($expectedData1); $actualData = 2.0; $expectedData2 = 2; assertsDouble($actualData)->isLessThanOrEqualTo($expectedData2); // and these should fail try { $expectedData3 = 1; assertsDouble($actualData)->isLessThanOrEqualTo($expectedData3); } catch (Exception $e) { $checkpoint->test3Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test3Passed"); assertsBoolean($checkpoint->test3Passed)->isTrue(); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $actualData = 2.0; $expectedData1 = 3; assertsDouble($actualData)->isLessThan($expectedData1); // and these should fail try { $expectedData2 = 2; assertsDouble($actualData)->isLessThan($expectedData2); } catch (Exception $e) { $checkpoint->test2Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Passed"); assertsBoolean($checkpoint->test2Passed)->isTrue(); });
$checkpoint = getCheckpoint(); // this should pass $expectedData1 = 1.1; $actualData1 = 1.1; assertsDouble($actualData1)->equals($expectedData1); // and these should fail try { $expectedData2 = 1.12; assertsDouble($actualData1)->equals($expectedData2); } catch (Exception $e) { $checkpoint->test2Passed = true; } // and these should fail try { $expectedData3 = 0; assertsDouble($actualData1)->equals($expectedData3); } catch (Exception $e) { $checkpoint->test3Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Passed"); assertsBoolean($checkpoint->test2Passed)->isTrue(); assertsObject($checkpoint)->hasAttribute("test3Passed"); assertsBoolean($checkpoint->test3Passed)->isTrue();
} try { $intData = 11; assertsDouble($intData)->isNotNull(); } catch (Exception $e) { $checkpoint->intTest2Passed = true; } try { $objectData = new stdClass(); assertsDouble($objectData)->isNotNull(); } catch (Exception $e) { $checkpoint->objectTestPassed = true; } try { $stringData = ""; assertsDouble($stringData)->isNotNull(); } catch (Exception $e) { $checkpoint->stringTestPassed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("nullTestPassed"); assertsBoolean($checkpoint->nullTestPassed)->isTrue(); assertsObject($checkpoint)->hasAttribute("arrayTestPassed"); assertsBoolean($checkpoint->arrayTestPassed)->isTrue();
public function metricAverageDoesntExceed($metric, $expectedAverage, $startTime, $endTime) { // when are we looking for? $humanStartTime = date('Y-m-d H:i:s', $startTime); $humanEndTime = date('Y-m-d H:i:s', $endTime); // what are we doing? $log = usingLog()->startAction("ensure metric '{$metric}' average never exceeds value '{$expectedAverage}' between '{$humanStartTime}' and '{$humanEndTime}'"); // get the data from graphite $data = fromGraphite()->getDataFor($metric, $startTime, $endTime); // do we *have* any data? if (empty($data) || !isset($data[0]->target, $data[0]->datapoints)) { // graphite returns an empty data set when there is no data // // NOTE: this can also happen when the test is asking for // the wrong metric :( if ($expectedAverage !== 0) { // we were expecting there to be some data throw new E5xx_ExpectFailed(__METHOD__, "data for metric '{$metric}'", "no data available for metric '{$metric}'"); } // if we get here, it's reasonable to assume that everything is // as it should be $log->endAction("no data available for metric '{$metric}'; assuming success"); return; } // we have data ... let's make sure we're happy with it $total = 0; $count = 0; foreach ($data[0]->datapoints as $datapoint) { if ($datapoint[0] !== null) { $total += $datapoint[0]; $count++; } } // what is the average? $average = $total / $count; // are we happy? assertsDouble($average)->isLessThanOrEqualTo($expectedAverage); // all done $log->endAction("data was available, metric '{$metric}' never exceeds '{$expectedAverage}'"); return; }
// // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // these should pass $actualData = 2.0; $expectedData1 = 1; assertsDouble($actualData)->isGreaterThanOrEqualTo($expectedData1); $actualData = 2.0; $expectedData2 = 2; assertsDouble($actualData)->isGreaterThanOrEqualTo($expectedData2); // and these should fail try { $expectedData3 = 3; assertsDouble($actualData)->isGreaterThanOrEqualTo($expectedData3); } catch (Exception $e) { $checkpoint->test3Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test3Passed"); assertsBoolean($checkpoint->test3Passed)->isTrue(); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $expectedData1 = 1.1; $actualData1 = 1.12; assertsDouble($actualData1)->doesNotEqual($expectedData1); // and these should fail try { $expectedData2 = 1.12; assertsDouble($actualData1)->doesNotEqual($expectedData2); } catch (Exception $e) { $checkpoint->test2Passed = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Passed"); assertsBoolean($checkpoint->test2Passed)->isTrue(); });