Skip to content

Commit

Permalink
Merge branch 'MDL-75231-master' of https://github.com/lameze/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Sep 6, 2022
2 parents 9bc847b + 8f078a2 commit 7b410fb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/tests/filelib_test.php
Expand Up @@ -1863,6 +1863,7 @@ public function test_file_is_draft_areas_limit_reached() {
}

// Burst up to the capacity and make sure that the bucket allows it.
$burststart = microtime();
for ($i = 0; $i < $capacity; $i++) {
if ($i) {
sleep(1); // A little delay so we have different timemodified value for files.
Expand All @@ -1877,9 +1878,16 @@ public function test_file_is_draft_areas_limit_reached() {
// The bucket should be full after bursting.
$this->assertTrue(file_is_draft_areas_limit_reached($user->id));

// Calculate the time taken to burst up the bucket capacity.
$timetaken = microtime_diff($burststart, microtime());

// The bucket leaks so it shouldn't be full after a certain time.
// Reiterating that this test could have been faster if MDL-37327 was implemented.
sleep(ceil(1 / $leak) - ($capacity - 1));
// Items are added into the bucket at the rate of 1 item per second.
// One item leaks from the bucket every 1/$leak seconds.
// So it takes 1/$leak - ($capacity-1) seconds for the bucket to leak one item and not be full anymore.
$milliseconds = ceil(1000000 * ((1 / $leak) - ($capacity - 1)) - ($timetaken * 1000));
usleep($milliseconds);

$this->assertFalse(file_is_draft_areas_limit_reached($user->id));

// Only one item was leaked from the bucket. So the bucket should become full again if we add a single item to it.
Expand Down

0 comments on commit 7b410fb

Please sign in to comment.