Skip to content

Commit

Permalink
Merge branch 'MDL-60705-master' of https://github.com/sammarshallou/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Nov 7, 2017
2 parents 13b19e4 + 4017108 commit 8072eb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions search/tests/fixtures/mock_search_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class engine extends \core_search\engine {

/** @var int If set, waits when adding each document (microseconds) */
/** @var float If set, waits when adding each document (seconds) */
protected $adddelay = 0;

/** @var \core_search\document[] Documents added */
Expand Down Expand Up @@ -83,7 +83,7 @@ public function get_query_total_count() {
* @param float $seconds Delay in seconds for each document
*/
public function set_add_delay($seconds) {
$this->adddelay = (int)($seconds * 1000000);
$this->adddelay = $seconds;
}

/**
Expand Down
16 changes: 11 additions & 5 deletions search/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public function test_partial_indexing() {
$generator->get_plugin_generator('mod_forum')->create_discussion(['course' => $course->id,
'forum' => $forum->id, 'userid' => $USER->id, 'timemodified' => $now + 2,
'name' => 'Zombie']);
$generator->get_plugin_generator('mod_forum')->create_discussion(['course' => $course->id,
'forum' => $forum->id, 'userid' => $USER->id, 'timemodified' => $now + 2,
'name' => 'Werewolf']);
time_sleep_until($now + 3);

// Clear the count of added documents.
Expand Down Expand Up @@ -253,15 +256,18 @@ public function test_partial_indexing() {
$this->assertCount(1, $added);
$this->assertEquals('Vampire', $added[0]->get('title'));

// Index again with a 2 second limit - it will redo last post for safety (because of other
// Index again with a 3 second limit - it will redo last post for safety (because of other
// things possibly having the same time second), and then do the remaining one. (Note:
// because it always does more than one second worth of items, it would actually index 2
// posts even if the limit were less than 2.)
$search->index(false, 2);
// posts even if the limit were less than 2, we are testing it does 3 posts to make sure
// the time limiting is actually working with the specified time.)
$search->index(false, 3);
$added = $search->get_engine()->get_and_clear_added_documents();
$this->assertCount(2, $added);
$this->assertCount(3, $added);
$this->assertEquals('Toad', $added[0]->get('title'));
$this->assertEquals('Zombie', $added[1]->get('title'));
$remainingtitles = [$added[1]->get('title'), $added[2]->get('title')];
sort($remainingtitles);
$this->assertEquals(['Werewolf', 'Zombie'], $remainingtitles);
$this->assertFalse(get_config($componentname, $varname . '_partial'));

// Index again - there should be nothing to index this time.
Expand Down

0 comments on commit 8072eb1

Please sign in to comment.