Skip to content

Commit

Permalink
Feat--add-each_ok_and_error-return-policy (#255)
Browse files Browse the repository at this point in the history
* feat: add each_ok_and_error return policy

* feat: add each_ok_and_error return policy
  • Loading branch information
halajohn authored Nov 10, 2024
1 parent 91bf25d commit 20e8275
Show file tree
Hide file tree
Showing 28 changed files with 732 additions and 36 deletions.
2 changes: 1 addition & 1 deletion core/include_internal/ten_runtime/common/constant_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@
#define TEN_STR_RESULT_RETURN_POLICY "result_return_policy"
#define TEN_STR_FIRST_ERROR_OR_FIRST_OK "first_error_or_first_ok"
#define TEN_STR_FIRST_ERROR_OR_LAST_OK "first_error_or_last_ok"
#define TEN_STR_EACH_IMMEDIATELY "each_immediately"
#define TEN_STR_EACH_OK_AND_ERROR "each_ok_and_error"
4 changes: 2 additions & 2 deletions core/include_internal/ten_runtime/path/result_return_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ typedef enum TEN_RESULT_RETURN_POLICY {
// Similar to the above, except return the last received one.
TEN_RESULT_RETURN_POLICY_FIRST_ERROR_OR_LAST_OK,

// Return each result immediately as it is received.
TEN_RESULT_RETURN_POLICY_EACH_IMMEDIATELY,
// Return each result as it is received, regardless of its status.
TEN_RESULT_RETURN_POLICY_EACH_OK_AND_ERROR,

// More modes is allowed, and could be added here in case needed.
} TEN_RESULT_RETURN_POLICY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static void proxy_send_xxx_callback(ten_extension_t *extension,

Py_XDECREF(arglist);

bool is_final = ten_cmd_result_is_final(cmd_result, NULL);
if (is_final) {
bool is_completed = ten_cmd_result_is_completed(cmd_result, NULL);
if (is_completed) {
Py_XDECREF(cb_func);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_runtime/path/path_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ten_path_t *ten_path_group_resolve(ten_path_t *path, TEN_PATH_TYPE type) {
case TEN_RESULT_RETURN_POLICY_FIRST_ERROR_OR_LAST_OK:
return ten_path_group_resolve_in_one_fail_and_all_ok_return(members, type,
true);
case TEN_RESULT_RETURN_POLICY_EACH_IMMEDIATELY:
case TEN_RESULT_RETURN_POLICY_EACH_OK_AND_ERROR:
// In this policy, we return the current path immediately.
return path;
default:
Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_runtime/path/path_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ ten_shared_ptr_t *ten_path_table_determine_actual_cmd_result(
ten_path_group_t *path_group = ten_path_get_group(path);

switch (path_group->policy) {
case TEN_RESULT_RETURN_POLICY_EACH_IMMEDIATELY: {
case TEN_RESULT_RETURN_POLICY_EACH_OK_AND_ERROR: {
bool last_one =
ten_path_table_remove_path_from_group(self, path_type, path);

Expand Down
8 changes: 4 additions & 4 deletions core/src/ten_runtime/path/result_return_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ TEN_RESULT_RETURN_POLICY ten_result_return_policy_from_string(
} else if (ten_c_string_is_equal(policy_str,
TEN_STR_FIRST_ERROR_OR_LAST_OK)) {
return TEN_RESULT_RETURN_POLICY_FIRST_ERROR_OR_LAST_OK;
} else if (ten_c_string_is_equal(policy_str, TEN_STR_EACH_IMMEDIATELY)) {
return TEN_RESULT_RETURN_POLICY_EACH_IMMEDIATELY;
} else if (ten_c_string_is_equal(policy_str, TEN_STR_EACH_OK_AND_ERROR)) {
return TEN_RESULT_RETURN_POLICY_EACH_OK_AND_ERROR;
} else {
return TEN_RESULT_RETURN_POLICY_INVALID;
}
Expand All @@ -33,8 +33,8 @@ const char *ten_result_return_policy_to_string(
return TEN_STR_FIRST_ERROR_OR_FIRST_OK;
case TEN_RESULT_RETURN_POLICY_FIRST_ERROR_OR_LAST_OK:
return TEN_STR_FIRST_ERROR_OR_LAST_OK;
case TEN_RESULT_RETURN_POLICY_EACH_IMMEDIATELY:
return TEN_STR_EACH_IMMEDIATELY;
case TEN_RESULT_RETURN_POLICY_EACH_OK_AND_ERROR:
return TEN_STR_EACH_OK_AND_ERROR;
default:
return NULL;
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/ten_rust/src/json_schema/data/property.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"minLength": 1,
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
},
"result_return_policy": {
"type": "string",
"enum": [
"each_ok_and_error",
"first_error_or_first_ok",
"first_error_or_last_ok"
]
},
"valueType": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -310,6 +318,9 @@
"name": { // The api name should be alphanumericCharacters.
"$ref": "#/$defs/alphanumericCharacters"
},
"result_return_policy": {
"$ref": "#/$defs/result_return_policy"
},
"dest": {
"$ref": "#/$defs/dataDests"
}
Expand All @@ -329,6 +340,9 @@
"name": { // The api name should be alphanumericCharacters.
"$ref": "#/$defs/alphanumericCharacters"
},
"result_return_policy": {
"$ref": "#/$defs/result_return_policy"
},
"dest": {
"$ref": "#/$defs/cmdDests"
}
Expand Down
4 changes: 3 additions & 1 deletion tests/ten_runtime/integration/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ addopts =
--ignore=tests/ten_runtime/integration/python/go_app_async_extension_python/go_app_async_extension_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/multiple_results_python/multiple_results_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/multiple_results_python_1/multiple_results_python_1_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/multiple_results_python_2/multiple_results_python_2_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/multiple_results_python_3/multiple_results_python_3_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/resp_handler_yield_python/resp_handler_yield_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/send_cmd_discard_result_python/send_cmd_discard_result_python_app/ten_packages/extension/default_extension_python/tests/
--ignore=tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/extension/default_extension_python/tests/
Expand Down
4 changes: 3 additions & 1 deletion tests/ten_runtime/integration/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ group("python") {
"go_app_async_extension_python",
"large_json_python",
"multi_process_python",
"multiple_results_python",
"multiple_results_python_1",
"multiple_results_python_2",
"multiple_results_python_3",
"resp_handler_yield_python",
"send_cmd_discard_result_python",
"send_cmd_python",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import("//build/ten_runtime/feature/test.gni")
import("//build/ten_runtime/ten.gni")

ten_package_test_prepare_app("multiple_results_python_app") {
ten_package_test_prepare_app("multiple_results_python_1_app") {
src_app = "default_app_python"
src_app_language = "python"
generated_app_src_root_dir_name = "multiple_results_python_app"
generated_app_src_root_dir_name = "multiple_results_python_1_app"

replace_files_after_install_app = [
"multiple_results_python_app/manifest.json",
"multiple_results_python_app/property.json",
"multiple_results_python_1_app/manifest.json",
"multiple_results_python_1_app/property.json",
]

replace_files_after_install_all = [ "multiple_results_python_app/ten_packages/extension/default_extension_python/extension.py" ]
replace_files_after_install_all = [ "multiple_results_python_1_app/ten_packages/extension/default_extension_python/extension.py" ]

if (ten_enable_package_manager) {
deps = [
Expand All @@ -31,7 +31,7 @@ ten_package_test_prepare_app("multiple_results_python_app") {
}

ten_package_test_prepare_auxiliary_resources(
"multiple_results_python_test_files") {
"multiple_results_python_1_test_files") {
resources = [
"//tests/ten_runtime/integration/common=>common",
"__init__.py",
Expand All @@ -42,9 +42,9 @@ ten_package_test_prepare_auxiliary_resources(
}
}

group("multiple_results_python") {
group("multiple_results_python_1") {
deps = [
":multiple_results_python_app",
":multiple_results_python_test_files",
":multiple_results_python_1_app",
":multiple_results_python_1_test_files",
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Test multiple_results_python.
Test multiple_results_python_1.
"""

import subprocess
Expand All @@ -20,7 +20,7 @@ def http_request():
)


def test_multiple_results_python():
def test_multiple_results_python_1():
"""Test client and app server."""
base_path = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.join(base_path, "../../../../../")
Expand All @@ -40,20 +40,20 @@ def test_multiple_results_python():
my_env["PATH"] = os.path.join(venv_dir, "bin") + os.pathsep + my_env["PATH"]

if sys.platform == "win32":
print("test_multiple_results_python doesn't support win32")
print("test_multiple_results_python_1 doesn't support win32")
assert False
elif sys.platform == "darwin":
# client depends on some libraries in the TEN app.
my_env["DYLD_LIBRARY_PATH"] = os.path.join(
base_path, "multiple_results_python_app/lib"
base_path, "multiple_results_python_1_app/lib"
)
else:
# client depends on some libraries in the TEN app.
my_env["LD_LIBRARY_PATH"] = os.path.join(
base_path, "multiple_results_python_app/lib"
base_path, "multiple_results_python_1_app/lib"
)

app_root_path = os.path.join(base_path, "multiple_results_python_app")
app_root_path = os.path.join(base_path, "multiple_results_python_1_app")

tman_install_cmd = [
os.path.join(root_dir, "ten_manager/bin/tman"),
Expand All @@ -72,7 +72,7 @@ def test_multiple_results_python():
tman_install_process.wait()

bootstrap_cmd = os.path.join(
base_path, "multiple_results_python_app/bin/bootstrap"
base_path, "multiple_results_python_1_app/bin/bootstrap"
)

bootstrap_process = subprocess.Popen(
Expand All @@ -84,14 +84,14 @@ def test_multiple_results_python():
if os.path.exists(os.path.join(base_path, "use_asan_lib_marker")):
libasan_path = os.path.join(
base_path,
"multiple_results_python_app/ten_packages/system/ten_runtime/lib/libasan.so",
"multiple_results_python_1_app/ten_packages/system/ten_runtime/lib/libasan.so",
)

if os.path.exists(libasan_path):
my_env["LD_PRELOAD"] = libasan_path

server_cmd = os.path.join(
base_path, "multiple_results_python_app/bin/start"
base_path, "multiple_results_python_1_app/bin/start"
)

server = subprocess.Popen(
Expand All @@ -104,11 +104,11 @@ def test_multiple_results_python():

is_started = http.is_app_started("127.0.0.1", 8002, 30)
if not is_started:
print("The multiple_results_python is not started after 30 seconds.")
print("The multiple_results_python_1 is not started after 30 seconds.")

server.kill()
exit_code = server.wait()
print("The exit code of multiple_results_python: ", exit_code)
print("The exit code of multiple_results_python_1: ", exit_code)

assert exit_code == 0
assert 0
Expand All @@ -123,10 +123,12 @@ def test_multiple_results_python():
finally:
is_stopped = http.stop_app("127.0.0.1", 8002, 30)
if not is_stopped:
print("The multiple_results_python can not stop after 30 seconds.")
print(
"The multiple_results_python_1 can not stop after 30 seconds."
)
server.kill()

exit_code = server.wait()
print("The exit code of multiple_results_python: ", exit_code)
print("The exit code of multiple_results_python_1: ", exit_code)

assert exit_code == 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright © 2024 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/feature/test.gni")
import("//build/ten_runtime/ten.gni")

ten_package_test_prepare_app("multiple_results_python_2_app") {
src_app = "default_app_python"
src_app_language = "python"
generated_app_src_root_dir_name = "multiple_results_python_2_app"

replace_files_after_install_app = [
"multiple_results_python_2_app/manifest.json",
"multiple_results_python_2_app/property.json",
]

replace_files_after_install_all = [ "multiple_results_python_2_app/ten_packages/extension/default_extension_python/extension.py" ]

if (ten_enable_package_manager) {
deps = [
"//core/src/ten_manager",
"//packages/core_apps/default_app_python:upload_default_app_python_to_server",
"//packages/core_extensions/default_extension_python:upload_default_extension_python_to_server",
"//packages/example_extensions/simple_echo_cpp:upload_simple_echo_cpp_to_server",
"//packages/example_extensions/simple_http_server_cpp:upload_simple_http_server_cpp_to_server",
]
}
}

ten_package_test_prepare_auxiliary_resources(
"multiple_results_python_2_test_files") {
resources = [
"//tests/ten_runtime/integration/common=>common",
"__init__.py",
"test_case.py",
]
if (enable_sanitizer) {
resources += [ "//tests/ten_runtime/integration/tools/use_asan_lib_marker=>use_asan_lib_marker" ]
}
}

group("multiple_results_python_2") {
deps = [
":multiple_results_python_2_app",
":multiple_results_python_2_test_files",
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"dependencies": [
{
"type": "system",
"name": "ten_runtime",
"version": "0.3.0"
},
{
"type": "extension",
"name": "simple_http_server_cpp",
"version": "0.1.0"
},
{
"type": "extension",
"name": "default_extension_python",
"version": "0.3.0"
}
]
}
Loading

0 comments on commit 20e8275

Please sign in to comment.