ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 29 of file CallbackDurationTest.php.

Member Function Documentation

◆ getTestCallbackWithLength()

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

Definition at line 67 of file CallbackDurationTest.php.

67 : callable
68 {
69 return static function () use ($duration_in_ms, $should_halt): void {
70 usleep(1_000 * $duration_in_ms);
71 if ($should_halt) {
72 exit;
73 }
74 };
75 }
exit

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 52 of file CallbackDurationTest.php.

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

References $duration, and HTTP\Services\CallbackDurationTest\getTestCallbackWithLength().

+ Here is the call graph for this function:

◆ testCallbackStretchingWithTooLongExecutionTime()

HTTP\Services\CallbackDurationTest::testCallbackStretchingWithTooLongExecutionTime ( )

Definition at line 42 of file CallbackDurationTest.php.

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

References $duration, and HTTP\Services\CallbackDurationTest\getTestCallbackWithLength().

+ Here is the call graph for this function:

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