Skip to content
Snippets Groups Projects
Commit 5b6534ad authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Improve the healthcheck: actively test the optional libraries are really being...

Improve the healthcheck: actively test the optional libraries are really being loaded into sessions.
parent 8e39d56f
No related branches found
No related tags found
No related merge requests found
......@@ -642,6 +642,10 @@ $string['healthchecksstackmaximanotupdated'] = 'It seems that STACK has not been
$string['healthchecksstackmaximatooold'] = 'So old the version is unknown!';
$string['healthchecksstackmaximaversionmismatch'] = 'The version of the STACK-Maxima libraries being used ({$a->usedversion}) does not match what is expected ({$a->expectedversion}) by this version of the STACK question type. {$a->fix}';
$string['healthchecksstackmaximaversionok'] = 'Correct and expected STACK-Maxima library version being used ({$a->usedversion}).';
$string['healthchecksstacklibrariesworking'] = 'Maxima optional libraries';
$string['healthchecksstacklibrariesworkingok'] = 'Maxima optional libraries appear to be actually loading correctly.';
$string['healthchecksstacklibrariesworkingsession'] = 'Checking the optional maxima libraries threw the following error: {$a->err}';
$string['healthchecksstacklibrariesworkingfailed'] = 'The following optional maxima library/libraries appear not to load: {$a->err}. Try recreating your Maxima image.';
$string['healthuncached'] = 'Uncached CAS call';
$string['healthuncachedintro'] = 'This section always sends a genuine call to the CAS, regardless of the current cache settings. This is needed to ensure the connection to the CAS is really currently working.';
$string['healthuncachedstack_CAS_ok'] = 'CAS returned data as expected. You have a live connection to the CAS.';
......
......@@ -56,16 +56,9 @@ class stack_cas_healthcheck {
$test['details'] = null;
$this->tests[] = $test;
// List the requested maxima packages in ths summary.
$test = array();
$test['tag'] = 'settingmaximalibraries';
$test['result'] = null;
$test['summary'] = $config->maximalibraries;
$test['details'] = null;
$this->tests[] = $test;
// Check if the current options for library packages are permitted (maximalibraries).
list($result, $message) = stack_cas_configuration::validate_maximalibraries();
list($result, $message, $livetestcases) = stack_cas_configuration::validate_maximalibraries();
// The livetestcases are used below, once we have a live maxima or image ready to test.
if (!$result) {
$this->ishealthy = false;
$test = array();
......@@ -191,6 +184,57 @@ class stack_cas_healthcheck {
$this->tests[] = $test;
}
// Check that each library really is loaded into the current connection.
if ($this->ishealthy) {
// At this point everything _should_ be working so we use a regular session connection.
$s = array();
foreach ($livetestcases as $lib => $test) {
$s[$lib] = stack_ast_container::make_from_teacher_source($test, 'test_library', new stack_cas_security());
}
$session = new stack_cas_session2($s);
if ($session->get_valid()) {
$session->instantiate();
}
$result = true;
$message = 'healthchecksstacklibrariesworkingok';
$details = '';
if ($session->is_instantiated()) {
$failed = array();
foreach ($livetestcases as $lib => $test) {
// We assume the maxima expression testing each library must return true if and only if it works.
if ($s[$lib]->get_value() != 'true') {
$failed[] = $lib;
}
}
if ($failed != array()) {
$this->ishealthy = false;
$result = false;
$message = 'healthchecksstacklibrariesworkingfailed';
$details = array('err' => implode(', ', $failed));
}
} else {
$this->ishealthy = false;
$result = false;
$message = 'healthchecksstacklibrariesworkingsession';
$details = array('err' => $session->get_errors(true));
}
$test = array();
$test['tag'] = 'healthchecksstacklibrariesworking';
$test['result'] = $result;
$test['summary'] = stack_string($message, $details);
$test['details'] = stack_string($message, $details);
$this->tests[] = $test;
}
// List the requested maxima packages in the summary.
$test = array();
$test['tag'] = 'settingmaximalibraries';
$test['result'] = null;
$test['summary'] = $config->maximalibraries;
$test['details'] = null;
$this->tests[] = $test;
// Record whether caching is taking place in the summary.
$test = array();
$test['tag'] = 'settingcasresultscache';
......
......@@ -28,8 +28,19 @@ require_once(__DIR__ . '/cassession2.class.php');
class stack_cas_configuration {
protected static $instance = null;
/** @var array This variable controls which optional packages are supported by STACK. */
public static $maximalibraries = array('stats', 'distrib', 'descriptive', 'simplex');
/**
* @var array This variable controls which optional packages are supported by STACK.
* Each key is the library name, and the value checks the library appears loaded and working.
* Each must return a boolean value true if and only if the library is loaded.
*
* When adding a library update the language string settingmaximalibraries_desc.
**/
public static $maximalibraries = array(
'stats' => 'is(op(test_mean([1,2,3]))=inference_result)',
'distrib' => 'not(is(op(pdf_normal(1,3,1))=pdf_normal))',
'descriptive' => 'atom(mean([1,2,3.2]))',
'simplex' => 'floatnump(epsilon_lp)'
);
protected $settings;
......@@ -261,7 +272,7 @@ END;
foreach ($maximalib as $lib) {
$lib = trim($lib);
// Only include and load supported libraries.
if (in_array($lib, self::$maximalibraries)) {
if (in_array($lib, array_keys(self::$maximalibraries))) {
$contents .= 'load("'.$lib.'")$'."\n";
}
}
......@@ -337,19 +348,27 @@ END;
protected function get_validate_maximalibraries() {
$valid = true;
// Hold test cases for libraries to test.
$livetestcases = array();
$message = '';
$permittedlibraries = array_keys(self::$maximalibraries);
$maximalib = $this->settings->maximalibraries;
$maximalib = explode(',', $maximalib);
foreach ($maximalib as $lib) {
$lib = trim($lib);
// Only include and load supported libraries.
if ($lib !== '' && !in_array($lib, self::$maximalibraries)) {
if ($lib !== '') {
if (in_array($lib, $permittedlibraries)) {
// We need to check the library really loaded in the Maxima image.
$livetestcases[$lib] = self::$maximalibraries[$lib];
} else {
$valid = false;
$a = $lib;
$message .= stack_string('settingmaximalibraries_error', $a);
}
}
return(array($valid, $message));
}
return(array($valid, $message, $livetestcases));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment