Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
7 changes: 7 additions & 0 deletions tests/python/tests/coroutine/php/data/component-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
entry: script
components:
script:
image: KPHP
scope: Request
args: {}
links: {}
54 changes: 54 additions & 0 deletions tests/python/tests/coroutine/php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

function test_get_running_fork_id() {
$f = function() {
// 1. Non-"main" fork. Before std function which is coroutine
$before = (int)get_running_fork_id();

sched_yield_sleep(0.01);

$nested_f = function () {
// 2. Yet another non-"main" fork. Before std function which is coroutine
$before = (int)get_running_fork_id();
sched_yield_sleep(0.01);
assert_fork_id($before);
return null;
};

assert_fork_id($before);
$fut = fork($nested_f());
assert_fork_id($before);
wait($fut);
assert_fork_id($before);
return null;
};
$fut = fork($f());

// 3. "main" fork. Before std function which is coroutine
$before = (int)get_running_fork_id();
sched_yield_sleep(0.01);
assert_fork_id($before);
wait($fut);
assert_fork_id($before);
}


function assert_fork_id(int $expected_fork_id) {
$current_fork_id = (int)get_running_fork_id();
if ($current_fork_id != $expected_fork_id) {
critical_error("unexpected fork id, expected: " . $expected_fork_id . " got: " . $current_fork_id);
}
}

function main() {
switch ($_SERVER["PHP_SELF"]) {
case "/test_get_running_fork_id": {
test_get_running_fork_id();
return;
}
}

critical_error("unknown test");
}

main();
17 changes: 17 additions & 0 deletions tests/python/tests/coroutine/test_get_running_fork_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import socket
import pytest

from python.lib.testcase import WebServerAutoTestCase
from python.lib.http_client import RawResponse

class TestErrors(WebServerAutoTestCase):
@classmethod
def extra_class_setup(cls):
if not cls.should_use_k2():
cls.web_server.update_options({
"--workers-num": 1
})

def test_get_running_fork_id(self):
response = self.web_server.http_request(uri="/test_get_running_fork_id", method='GET')
self.assertEqual(200, response.status_code)
Loading