From eb9a66edaa09d28a14844accc2a3eedb4ed8f279 Mon Sep 17 00:00:00 2001 From: Ahmadreza Bashari Date: Mon, 25 Nov 2024 23:13:40 +0330 Subject: [PATCH] Add a test to verify that child processes are isolated --- tests/ForkTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/ForkTest.php b/tests/ForkTest.php index cb0bf2e..f1a6436 100644 --- a/tests/ForkTest.php +++ b/tests/ForkTest.php @@ -107,6 +107,30 @@ function () { expect($value)->toEqual(2); }); +test('events of child processes are isolated from each other', function () { + $value = 2; + Fork::new() + ->before(function () use(&$value) { + $value++; + global $x; + $x=1; + }) + ->after(function () use(&$value) { + $value++; + global $x; + expect($x)->toEqual(2); + }) + ->run(function () { + global $x; + $x++; + }, function () { + global $x; + $x++; + }); + + expect($value)->toEqual(2); +}); + it('will not hang by truncating the result when large output is returned') ->expect( Fork::new()->run(