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

Use the "Bulktest" script to also seed the cache with the question, note and worked solution.

parent 07edecff
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,8 @@ echo $OUTPUT->header();
echo $OUTPUT->heading($title);
// Run the tests.
list($allpassed, $failingtests) = $bulktester->run_all_tests_for_context($context);
list($allpassed, $failingtests, $notests) = $bulktester->run_all_tests_for_context($context);
// Display the final summary.
$bulktester->print_overall_result($allpassed, $failingtests);
$bulktester->print_overall_result($allpassed, $failingtests, $notests);
echo $OUTPUT->footer();
......@@ -73,11 +73,11 @@ foreach ($bulktester->get_stack_questions_by_context() as $contextid => $numstac
array('startfromcontextid' => $testcontext->id)),
stack_string('bulktestcontinuefromhere')));
list($passed, $failingtests) = $bulktester->run_all_tests_for_context($testcontext);
list($passed, $failingtests, $notests) = $bulktester->run_all_tests_for_context($testcontext);
$allpassed = $allpassed && $passed;
$allfailingtests = array_merge($allfailingtests, $failingtests);
}
// Display the final summary.
$bulktester->print_overall_result($allpassed, $allfailingtests);
$bulktester->print_overall_result($allpassed, $allfailingtests, $notests);
echo $OUTPUT->footer();
......@@ -79,11 +79,10 @@ $deploytxt = optional_param('deploymany', null, PARAM_TEXT);
$starttime = time();
// The number of seconds we devote to deploying before moving on. Prevents system hangging.
// Note, in "safe mode" the set time limit function has no effect.
$maxtime = 25;
if (!ini_get('safe_mode')) {
$maxtime = 180;
set_time_limit($maxtime + 5);
}
flush(); // Force output to prevent timeouts and to make progress clear.
core_php_time_limit::raise($maxtime); // Prevent PHP timeouts.
gc_collect_cycles(); // Because PHP's default memory management is rubbish.
if (!is_null($deploy)) {
......
......@@ -61,10 +61,10 @@ index 7974af2..a6614f2 100644
+$bulktester = new stack_bulk_tester();
+
// Run the tests.
list($allpassed, $failingtests) = $bulktester->run_all_tests_for_context($context);
list($allpassed, $failingtests, $notests) = $bulktester->run_all_tests_for_context($context);
// Display the final summary.
$bulktester->print_overall_result($allpassed, $failingtests);
$bulktester->print_overall_result($allpassed, $failingtests, $notests);
+
+// Switch back to the read DB.
+$DB = $bulktestrealdb;
......
......@@ -543,6 +543,7 @@ $string['stackInstall_testsuite_choose'] = 'Please choose an answer test.';
$string['stackInstall_testsuite_pass'] = 'All tests passed!';
$string['stackInstall_testsuite_fail'] = 'Not all tests passed!';
$string['stackInstall_testsuite_failures'] = 'Tests that failed';
$string['stackInstall_testsuite_notests'] = 'Questions with no tests: please add some!';
$string['answertest'] = 'Answer test';
$string['answertest_help'] = 'An answer test is used to compare two expressions to establish whether they satisfy some mathematical criteria.';
$string['answertest_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Answer_tests.md';
......
......@@ -819,9 +819,11 @@ class qtype_stack extends question_type {
array('questionid' => $questionid), 'testcase', 'testcase, 1');
$testcases = array();
foreach ($testcasenumbers as $number => $notused) {
if (array_key_exists($number, $testinputs)) {
$testcase = new stack_question_test($testinputs[$number]);
$testcases[$number] = $testcase;
}
}
$expecteddata = $DB->get_records('qtype_stack_qtest_expected',
array('questionid' => $questionid), 'testcase, prtname');
......
......@@ -66,6 +66,7 @@ class stack_bulk_tester {
}
$allpassed = true;
$failingtests = array();
$notests = array();
foreach ($categories as $key => $category) {
list($categoryid) = explode(',', $key);
......@@ -80,16 +81,22 @@ class stack_bulk_tester {
echo html_writer::tag('p', stack_string('replacedollarscount', count($questionids)));
foreach ($questionids as $questionid => $name) {
$question = question_bank::load_question($questionid);
$questionname = format_string($name);
foreach ($question->deployedseeds as $seed) {
$this->qtype_stack_seed_cache($question, $seed);
}
$tests = question_bank::get_qtype('stack')->load_question_tests($questionid);
if (!$tests) {
echo $OUTPUT->heading(html_writer::link(new moodle_url($questiontestsurl,
array('questionid' => $questionid)), format_string($name)), 4);
$questionnamelink = html_writer::link(new moodle_url($questiontestsurl,
array('questionid' => $questionid)), format_string($name));
$notests[] = $questionnamelink;
echo $OUTPUT->heading($questionnamelink, 4);
echo html_writer::tag('p', stack_string('bulktestnotests'));
continue;
}
$question = question_bank::load_question($questionid);
$questionname = format_string($name);
$previewurl = new moodle_url($questiontestsurl, array('questionid' => $questionid));
if (empty($question->deployedseeds)) {
$questionnamelink = html_writer::link($previewurl, $questionname);
......@@ -116,8 +123,7 @@ class stack_bulk_tester {
}
}
}
return array($allpassed, $failingtests);
return array($allpassed, $failingtests, $notests);
}
/**
......@@ -172,13 +178,55 @@ class stack_bulk_tester {
return array($ok, $message);
}
/**
* Instantial the question to seed the cache.
*
* @param qtype_stack_question $question the question to test.
* @param int|null $seed if we want to force a particular version.
* @return array with two elements:
* bool true if the tests passed, else false.
* sring message summarising the number of passes and fails.
*/
public function qtype_stack_seed_cache($question, $seed = null, $quiet = false) {
flush(); // Force output to prevent timeouts and to make progress clear.
core_php_time_limit::raise(10); // Prevent PHP timeouts.
gc_collect_cycles(); // Because PHP's default memory management is rubbish.
// Prepare the question and a usage.
$qu = clone($question);
// Create the question usage we will use.
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', context_system::instance());
$quba->set_preferred_behaviour('adaptive');
if (!is_null($seed)) {
// This is a bit of a hack to force the question to use a particular seed,
// even if it is not one of the deployed seeds.
$qu->seed = (int) $seed;
}
$slot = $quba->add_question($qu, $qu->defaultmark);
$quba->start_question($slot);
// Prepare the display options.
$options = new question_display_options();
$options->readonly = true;
$options->flags = question_display_options::HIDDEN;
$options->suppressruntestslink = true;
// Create the question text, question note and worked solutions.
// This involves instantiation, which seeds the CAS cache in the cases when we have no tests.
$renderquestion = $quba->render_question($slot, $options);
$workedsolution = $qu->get_generalfeedback_castext();
$questionote = $qu->get_question_summary();
}
/**
* Print an overall summary, with a link back to the bulk test index.
*
* @param bool $allpassed whether all the tests passed.
* @param array $failingtests list of the ones that failed.
*/
public function print_overall_result($allpassed, $failingtests) {
public function print_overall_result($allpassed, $failingtests, $notests) {
global $OUTPUT;
echo $OUTPUT->heading(stack_string('overallresult'), 2);
if ($allpassed) {
......@@ -189,12 +237,23 @@ class stack_bulk_tester {
array('class' => 'overallresult fail'));
}
if (!empty($failingtests)) {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_failures'), 3);
echo html_writer::start_tag('ul');
foreach ($failingtests as $message) {
echo html_writer::tag('li', $message);
}
echo html_writer::end_tag('ul');
}
if (!empty($notests)) {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_notests'), 3);
echo html_writer::start_tag('ul');
foreach ($notests as $message) {
echo html_writer::tag('li', $message);
}
echo html_writer::end_tag('ul');
}
echo html_writer::tag('p', html_writer::link(new moodle_url('/question/type/stack/bulktestindex.php'),
get_string('back')));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment