ILIAS  release_8 Revision v8.24
HTTP\Services\CallbackDurationTest Class Reference
+ Inheritance diagram for HTTP\Services\CallbackDurationTest:
+ Collaboration diagram for HTTP\Services\CallbackDurationTest:

Public Member Functions

 testCallbackStretchingWithTooLongExecutionTime ()
 
 testCallbackStretching ()
 

Protected Member Functions

 getTestCallbackWithLength (int $duration_in_ms, bool $should_halt=false)
 

Detailed Description

Author
Thibeau Fuhrer thibe.nosp@m.au@s.nosp@m.r.sol.nosp@m.utio.nosp@m.ns

Definition at line 26 of file CallbackDurationTest.php.

Member Function Documentation

◆ getTestCallbackWithLength()

HTTP\Services\CallbackDurationTest::getTestCallbackWithLength ( int  $duration_in_ms,
bool  $should_halt = false 
)
protected

Definition at line 65 of file CallbackDurationTest.php.

65 : callable
66 {
67 return static function () use ($duration_in_ms, $should_halt) {
68 usleep(1_000 * $duration_in_ms);
69 if ($should_halt) {
70 exit;
71 }
72 };
73 }
exit
Definition: login.php:28

References exit.

Referenced by HTTP\Services\CallbackDurationTest\testCallbackStretching(), and HTTP\Services\CallbackDurationTest\testCallbackStretchingWithTooLongExecutionTime().

+ Here is the caller graph for this function:

◆ testCallbackStretching()

HTTP\Services\CallbackDurationTest::testCallbackStretching ( )

Definition at line 50 of file CallbackDurationTest.php.

50 : void
51 {
52 $callback = $this->getTestCallbackWithLength(1);
53 $duration = new CallbackDuration(3);
54
55 $start_time = microtime(true);
56 $duration->stretch($callback);
57 $end_time = microtime(true);
58
59 $elapsed_time = ($end_time - $start_time); // in microseconds (us)
60 $expected_duration_in_us = (0.002);
61
62 $this->assertGreaterThanOrEqual($expected_duration_in_us, ($end_time - $start_time));
63 }
getTestCallbackWithLength(int $duration_in_ms, bool $should_halt=false)

References HTTP\Services\CallbackDurationTest\getTestCallbackWithLength().

+ Here is the call graph for this function:

◆ testCallbackStretchingWithTooLongExecutionTime()

HTTP\Services\CallbackDurationTest::testCallbackStretchingWithTooLongExecutionTime ( )

Definition at line 40 of file CallbackDurationTest.php.

40 : void
41 {
42 $callback = $this->getTestCallbackWithLength(2);
43 $duration = new CallbackDuration(1);
44
45 $this->expectException(\RuntimeException::class);
46 $this->expectExceptionMessage("Execution of callback exceeded the given duration and could not be stretched.");
47 $duration->stretch($callback);
48 }

References HTTP\Services\CallbackDurationTest\getTestCallbackWithLength().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: