From 9849cbe860f6711f17046175fdf570be20abdb6b Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 5 Nov 2024 14:20:10 +0900 Subject: [PATCH] Add thread safety test for RayAOP interceptors Introduces a new PHPT test to ensure concurrent operation safety for RayAOP interceptors. This test registers multiple interceptors quickly and checks their execution to confirm the stability and correctness under concurrent conditions. --- tests/008-rayaop-thread-safety.phpt | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/008-rayaop-thread-safety.phpt diff --git a/tests/008-rayaop-thread-safety.phpt b/tests/008-rayaop-thread-safety.phpt new file mode 100644 index 0000000..b918e76 --- /dev/null +++ b/tests/008-rayaop-thread-safety.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test case: 008-rayaop-safety.phpt +RayAOP concurrent operation safety test +--SKIPIF-- + +--FILE-- +id = $id; + } + + public function intercept(object $object, string $method, array $params): mixed { + echo "Interceptor {$this->id} executing\n"; + $result = $object->$method(...$params); + echo "Interceptor {$this->id} completed\n"; + return $result; + } +} + +class TestClass { + public function method() { + echo "Original method executed\n"; + return true; + } +} + +// Test rapid registration and execution +method_intercept_init(); + +// Register multiple interceptors rapidly +for ($i = 0; $i < 3; $i++) { + $result = method_intercept( + TestClass::class, + 'method', + new SafetyTestInterceptor($i) + ); + echo "Interceptor {$i} registered: " . ($result ? 'true' : 'false') . "\n"; +} + +// Execute method multiple times +$test = new TestClass(); +for ($i = 0; $i < 2; $i++) { + echo "\nExecution #{$i}:\n"; + $result = $test->method(); + echo "Result: " . ($result ? 'true' : 'false') . "\n"; +} + +?> +--EXPECT-- +Interceptor 0 registered: true +Interceptor 1 registered: true +Interceptor 2 registered: true + +Execution #0: +Interceptor 2 executing +Original method executed +Interceptor 2 completed +Result: true + +Execution #1: +Interceptor 2 executing +Original method executed +Interceptor 2 completed +Result: true \ No newline at end of file