Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 23, 2024
1 parent 69effb7 commit ed50730
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 50 deletions.
9 changes: 5 additions & 4 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ void php_swoole_runtime_rinit() {
}

void php_swoole_runtime_rshutdown() {
#ifdef SW_THREAD
PHPCoroutine::disable_hook();
#endif

void *ptr;
ZEND_HASH_FOREACH_PTR(tmp_function_table, ptr) {
real_func *rf = reinterpret_cast<real_func *>(ptr);
Expand All @@ -255,17 +259,14 @@ void php_swoole_runtime_rshutdown() {
efree(tmp_function_table);
tmp_function_table = nullptr;

ori_func_handlers.clear();
clear_class_entries();
}

void php_swoole_runtime_mshutdown() {
#ifdef SW_USE_CURL
swoole_native_curl_mshutdown();
#endif
#ifdef SW_THREAD
PHPCoroutine::disable_hook();
#endif
ori_func_handlers.clear();
}

static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, zend_string **err) {
Expand Down
50 changes: 25 additions & 25 deletions ext-src/swoole_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ static void server_free_object(zend_object *object) {
sw_zend_fci_cache_discard((zend_fcall_info_cache *) serv->private_data_3);
efree(serv->private_data_3);
}
ZVAL_NULL(php_swoole_server_zval_ptr(serv));
for (int i = 0; i < PHP_SWOOLE_SERVER_CALLBACK_NUM; i++) {
zend_fcall_info_cache *fci_cache = property->callbacks[i];
if (fci_cache) {
Expand Down Expand Up @@ -2646,22 +2645,32 @@ static PHP_METHOD(swoole_server, start) {
ServerObject *server_object = server_fetch_object(Z_OBJ_P(php_swoole_server_zval_ptr(serv)));

#ifdef SW_THREAD
zval *_bootstrap = zend::object_get(ZEND_THIS, ZEND_STRL("bootstrap"));
zend_string *bootstrap = zend_string_dup(Z_STR_P(_bootstrap), 1);
zend_string *argv = nullptr;
zval thread_argv;

if (!ZVAL_IS_NULL(&server_object->init_arguments)) {
call_user_function(NULL, NULL, &server_object->init_arguments, &thread_argv, 0, NULL);
argv = php_swoole_thread_serialize(&thread_argv);
if (serv->is_thread_mode()) {
zval *_bootstrap = zend::object_get(ZEND_THIS, ZEND_STRL("bootstrap"));
zend_string *bootstrap = zend_string_dup(Z_STR_P(_bootstrap), 1);
zend_string *argv = nullptr;
zval thread_argv = {};

if (!ZVAL_IS_NULL(&server_object->init_arguments)) {
call_user_function(NULL, NULL, &server_object->init_arguments, &thread_argv, 0, NULL);
argv = php_swoole_thread_serialize(&thread_argv);
}

serv->worker_thread_start = [bootstrap, argv](const WorkerFn &fn) {
worker_thread_fn = fn;
zend_string *bootstrap_copy = zend_string_dup(bootstrap, 1);
zend_string *argv_copy = argv ? zend_string_dup(argv, 1) : nullptr;
php_swoole_thread_start(bootstrap_copy, argv_copy);
};

ON_SCOPE_EXIT {
zend_string_release(bootstrap);
if (argv) {
zend_string_release(argv);
}
zval_ptr_dtor(&thread_argv);
};
}

serv->worker_thread_start = [bootstrap, argv](const WorkerFn &fn) {
worker_thread_fn = fn;
zend_string *bootstrap_copy = zend_string_dup(bootstrap, 1);
zend_string *argv_copy = argv ? zend_string_dup(argv, 1) : nullptr;
php_swoole_thread_start(bootstrap_copy, argv_copy);
};
#endif

server_object->register_callback();
Expand All @@ -2670,15 +2679,6 @@ static PHP_METHOD(swoole_server, start) {
if (serv->start() < 0) {
php_swoole_fatal_error(E_ERROR, "failed to start server. Error: %s", sw_error);
}

#ifdef SW_THREAD
zend_string_release(bootstrap);
if (argv) {
zend_string_release(argv);
}
zval_ptr_dtor(&thread_argv);
#endif

RETURN_TRUE;
}

Expand Down
15 changes: 7 additions & 8 deletions tests/swoole_feature/cross_close/redis.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ $pm->parentFunc = function () use ($pm) {
echo "DONE\n";
$pm->kill();
});
$ret = $redis->get($pm->getRandomData());
echo "CLOSED\n";
Assert::assert(!$ret);
Assert::assert(!$redis->connected);
Assert::assert(in_array($redis->errType, [SWOOLE_REDIS_ERR_IO, SWOOLE_REDIS_ERR_EOF], true));
if ($redis->errType === SWOOLE_REDIS_ERR_IO) {
Assert::same($redis->errCode, SOCKET_ECANCELED);
try {
$ret = $redis->get($pm->getRandomData());
} catch (\RedisException $e) {
$ret = false;
echo "CLOSED\n";
}
Assert::assert(!$ret);
});
});
};
Expand All @@ -38,6 +37,7 @@ $pm->childFunc = function () use ($pm) {
Assert::assert($server->bind('127.0.0.1', $pm->getFreePort()));
Assert::assert($server->listen());
go(function () use ($pm, $server) {
$pm->wakeup();
if (Assert::assert(($conn = $server->accept()) && $conn instanceof Co\Socket)) {
switch_process();
$data = $conn->recv();
Expand All @@ -50,7 +50,6 @@ $pm->childFunc = function () use ($pm) {
}
$server->close();
});
$pm->wakeup();
});
};
$pm->childFirst();
Expand Down
9 changes: 5 additions & 4 deletions tests/swoole_feature/cross_close/redis_by_server.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ $pm->parentFunc = function () use ($pm) {
$redis = new \redis;
Assert::assert($redis->connect('127.0.0.1', $pm->getFreePort()));
echo "GET\n";
Assert::assert(!$redis->get($pm->getRandomData()));
echo "CLOSED\n";
Assert::same($redis->errType, SWOOLE_REDIS_ERR_EOF);
Assert::same($redis->errCode, SOCKET_ECONNRESET);
try {
$redis->get($pm->getRandomData());
} catch (\RedisException $e) {
echo "CLOSED\n";
}
$pm->kill();
echo "DONE\n";
});
Expand Down
19 changes: 11 additions & 8 deletions tests/swoole_timer/enable_coroutine2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ swoole_timer: enable_coroutine setting
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Swoole\Timer::set([
swoole_async_set([
'enable_coroutine' => false
]);
Swoole\Timer::after(1, function () {
$uid = Co::getuid();
echo "#{$uid}\n";
Swoole\Timer::set([
'enable_coroutine' => true
]);
Swoole\Timer::after(1, function () {
$uid = Co::getuid();
echo "#{$uid}\n";
});
});
Swoole\Event::wait();

swoole_async_set([
'enable_coroutine' => true
]);
Swoole\Timer::after(1, function () {
$uid = Co::getuid();
echo "#{$uid}\n";
});
Swoole\Event::wait();
?>
--EXPECT--
#-1
Expand Down
1 change: 0 additions & 1 deletion tests/swoole_timer/function_alias.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ swoole_timer: function alias
require __DIR__ . '/../include/bootstrap.php';

var_dump(
function_exists('swoole_timer_set') &&
function_exists('swoole_timer_after') &&
function_exists('swoole_timer_tick') &&
function_exists('swoole_timer_exists') &&
Expand Down

0 comments on commit ed50730

Please sign in to comment.