Skip to content

Commit cf05791

Browse files
authored
refactor: remove extension group name from message handling functions and update related tests (#774)
1 parent 918dc52 commit cf05791

File tree

319 files changed

+601
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+601
-681
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"request": "launch",
138138
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
139139
"args": [
140-
"--gtest_filter=ExtensionTest.CommandInvalidExtensionGroup"
140+
"--gtest_filter=BasicTest.ThrowExceptionInExtension"
141141
],
142142
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
143143
"env": {

core/include/ten_runtime/binding/cpp/detail/extension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class extension_t : public binding_handle_t {
133133
TEN_ASSERT(stop_graph_cmd, "Should not happen.");
134134

135135
ten_msg_clear_and_set_dest(stop_graph_cmd, "localhost", nullptr, nullptr,
136-
nullptr, nullptr);
136+
nullptr);
137137
ten_env_send_cmd(ten_env.get_c_ten_env(), stop_graph_cmd, nullptr, nullptr,
138138
nullptr, nullptr);
139139
ten_shared_ptr_destroy(stop_graph_cmd);

core/include/ten_runtime/binding/cpp/detail/msg/msg.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class msg_t {
5656
return ten_msg_get_name(c_msg);
5757
}
5858

59-
bool set_dest(const char *uri, const char *graph,
60-
const char *extension_group_name, const char *extension_name,
59+
bool set_dest(const char *uri, const char *graph, const char *extension_name,
6160
error_t *err = nullptr) const {
6261
TEN_ASSERT(c_msg, "Should not happen.");
6362

@@ -70,7 +69,7 @@ class msg_t {
7069
}
7170

7271
return ten_msg_clear_and_set_dest(
73-
c_msg, uri, graph, extension_group_name, extension_name,
72+
c_msg, uri, graph, extension_name,
7473
err != nullptr ? err->get_c_error() : nullptr);
7574
}
7675

core/include/ten_runtime/msg/msg.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ TEN_RUNTIME_API ten_value_t *ten_msg_peek_property(ten_shared_ptr_t *self,
7474
const char *path,
7575
ten_error_t *err);
7676

77-
TEN_RUNTIME_API bool ten_msg_clear_and_set_dest(
78-
ten_shared_ptr_t *self, const char *app_uri, const char *graph_id,
79-
const char *extension_group_name, const char *extension_name,
80-
ten_error_t *err);
77+
TEN_RUNTIME_API bool ten_msg_clear_and_set_dest(ten_shared_ptr_t *self,
78+
const char *app_uri,
79+
const char *graph_id,
80+
const char *extension_name,
81+
ten_error_t *err);
8182

8283
TEN_RUNTIME_API bool ten_msg_from_json(ten_shared_ptr_t *self, ten_json_t *json,
8384
ten_error_t *err);

core/include_internal/ten_runtime/msg/msg.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ TEN_RUNTIME_PRIVATE_API void ten_msg_set_src_to_extension_group(
9191
TEN_RUNTIME_PRIVATE_API void ten_msg_clear_and_set_dest_from_msg_src(
9292
ten_shared_ptr_t *self, ten_shared_ptr_t *cmd);
9393

94-
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_add_dest(
95-
ten_msg_t *self, const char *app_uri, const char *graph_id,
96-
const char *extension_group_name, const char *extension_name);
94+
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_add_dest(ten_msg_t *self,
95+
const char *app_uri,
96+
const char *graph_id,
97+
const char *extension_name);
9798

9899
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_clear_dest(ten_msg_t *self);
99100

core/src/ten_manager/src/fs/file_watcher.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ async fn watch_file_task(
184184
loop {
185185
// Wait for stop or the next check interval.
186186
tokio::select! {
187-
_ = &mut stop_rx => break,
187+
_ = &mut stop_rx => {
188+
eprintln!("Stopping file watcher");
189+
break;
190+
},
188191
_ = tokio::time::sleep(options.check_interval) => {
189192
// Check if the file has been rotated or truncated.
190193
match std::fs::metadata(&path) {
@@ -217,6 +220,7 @@ async fn watch_file_task(
217220
if curr_len > last_pos {
218221
// Read the new part.
219222
if let Err(e) = file.seek(SeekFrom::Start(last_pos)) {
223+
eprintln!("Error seeking to position: {}", e);
220224
let _ = content_tx.send(Err(anyhow::anyhow!(e))).await;
221225
break;
222226
}
@@ -231,13 +235,15 @@ async fn watch_file_task(
231235
}
232236
Ok(_) => {}
233237
Err(e) => {
238+
eprintln!("Error reading from file: {}", e);
234239
let _ = content_tx.send(Err(anyhow::anyhow!(e))).await;
235240
break;
236241
}
237242
}
238243
} else {
239244
// Reached EOF, check if the timeout has been reached.
240245
if Instant::now().duration_since(last_activity) > options.timeout {
246+
eprintln!("Timeout reached, breaking");
241247
break;
242248
}
243249
}

core/src/ten_manager/tests/test_case/fs/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,40 @@ mod tests {
2727
temp_file.write_all(test_content)?;
2828
temp_file.flush()?;
2929

30-
// Create options with shorter timeout for testing
30+
// Create options with shorter timeout for testing.
3131
let options = FileWatchOptions {
3232
timeout: Duration::from_secs(5),
3333
buffer_size: 1024,
3434
check_interval: Duration::from_millis(100),
3535
};
3636

37-
// Start watching the file
37+
// Start watching the file.
3838
let mut stream =
3939
watch_file(temp_file.path(), Some(options)).await?;
4040

41-
// Get the first chunk
41+
// Get the first chunk.
4242
let chunk = stream.next().await.expect("Should receive data")?;
4343
assert_eq!(chunk, test_content);
4444

45-
// Write more content to the file
45+
// Write more content to the file.
4646
let more_content = b"More content!";
4747
temp_file.write_all(more_content)?;
4848
temp_file.flush()?;
4949

50-
// Get the second chunk
51-
let chunk =
52-
stream.next().await.expect("Should receive more data")?;
53-
assert_eq!(chunk, more_content);
50+
// Get the second chunk.
51+
let chunk = stream.next().await;
52+
match chunk {
53+
Some(chunk) => match chunk {
54+
Ok(chunk) => assert_eq!(chunk, more_content),
55+
Err(e) => panic!("Should receive more data: {}", e),
56+
},
57+
None => {
58+
panic!("Should receive more data");
59+
}
60+
}
5461

55-
// Stop watching
62+
// Stop watching.
63+
println!("Stopping stream");
5664
stream.stop();
5765

5866
Ok(())

core/src/ten_runtime/addon/addon.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,24 @@ static void ten_app_create_addon_instance(ten_app_t *app,
373373
ten_string_get_raw_str(&addon_context->instance_name);
374374
TEN_ASSERT(instance_name, "Should not happen.");
375375

376-
if (ten_c_string_is_empty(addon_name) ||
377-
ten_c_string_is_empty(instance_name)) {
378-
TEN_LOGI(
379-
"The addon name or instance name is empty, will not create the addon "
380-
"instance.");
376+
if (addon_context->flow ==
377+
TEN_ADDON_CONTEXT_FLOW_ENGINE_CREATE_EXTENSION_GROUP) {
378+
if (ten_c_string_is_empty(addon_name)) {
379+
TEN_LOGI("The addon name is empty, will not create the extension group.");
381380

382-
ten_app_notify_create_addon_instance_failed(app, addon_context);
383-
return;
381+
ten_app_notify_create_addon_instance_failed(app, addon_context);
382+
return;
383+
}
384+
} else {
385+
if (ten_c_string_is_empty(addon_name) ||
386+
ten_c_string_is_empty(instance_name)) {
387+
TEN_LOGI(
388+
"The addon name or instance name is empty, will not create the addon "
389+
"instance.");
390+
391+
ten_app_notify_create_addon_instance_failed(app, addon_context);
392+
return;
393+
}
384394
}
385395

386396
TEN_LOGD("Try to find addon for %s", addon_name);

core/src/ten_runtime/app/predefined_graph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ ten_app_build_start_graph_cmd_to_start_predefined_graph(
8282
ten_shared_ptr_t *start_graph_cmd = ten_cmd_start_graph_create();
8383
TEN_ASSERT(start_graph_cmd, "Should not happen.");
8484

85-
ten_msg_clear_and_set_dest(start_graph_cmd, app_uri, NULL, NULL, NULL, err);
85+
ten_msg_clear_and_set_dest(start_graph_cmd, app_uri, NULL, NULL, err);
8686

8787
void *json_ctx = ten_json_create_new_ctx();
8888
ten_json_t start_graph_cmd_json = TEN_JSON_INIT_VAL(json_ctx, true);
8989
ten_json_init_object(&start_graph_cmd_json);
9090

9191
ten_json_t ten_json = TEN_JSON_INIT_VAL(json_ctx, false);
92-
bool success = ten_json_object_peek_or_create_object(
93-
&start_graph_cmd_json, TEN_STR_TEN, &ten_json);
92+
bool success = ten_json_object_peek_or_create_object(&start_graph_cmd_json,
93+
TEN_STR_TEN, &ten_json);
9494
TEN_ASSERT(success, "Should not happen.");
9595

9696
ten_json_t nodes_json = TEN_JSON_INIT_VAL(json_ctx, false);
@@ -193,7 +193,7 @@ static void ten_app_start_auto_start_predefined_graph_result_handler(
193193

194194
ten_shared_ptr_t *close_app_cmd = ten_cmd_close_app_create();
195195
ten_msg_clear_and_set_dest(close_app_cmd, ten_string_get_raw_str(&app->uri),
196-
NULL, NULL, NULL, err);
196+
NULL, NULL, err);
197197
ten_env_send_cmd(ten_env, close_app_cmd, NULL, NULL, NULL, err);
198198
}
199199
}

core/src/ten_runtime/binding/go/interface/ten_runtime/msg.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ type Msg interface {
4646

4747
GetName() (string, error)
4848
SetDest(
49-
appUri string,
50-
graphId string,
51-
extensionGroup string,
49+
appURI string,
50+
graphID string,
5251
extension string,
5352
) error
5453

@@ -205,22 +204,19 @@ func (p *msg) GetName() (string, error) {
205204
}
206205

207206
func (p *msg) SetDest(
208-
appUri string,
209-
graphId string,
210-
extensionGroup string,
207+
appURI string,
208+
graphID string,
211209
extension string,
212210
) error {
213211
defer p.keepAlive()
214212

215213
err := withCGOLimiter(func() error {
216214
apiStatus := C.ten_go_msg_set_dest(
217215
p.cPtr,
218-
unsafe.Pointer(unsafe.StringData(appUri)),
219-
C.int(len(appUri)),
220-
unsafe.Pointer(unsafe.StringData(graphId)),
221-
C.int(len(graphId)),
222-
unsafe.Pointer(unsafe.StringData(extensionGroup)),
223-
C.int(len(extensionGroup)),
216+
unsafe.Pointer(unsafe.StringData(appURI)),
217+
C.int(len(appURI)),
218+
unsafe.Pointer(unsafe.StringData(graphID)),
219+
C.int(len(graphID)),
224220
unsafe.Pointer(unsafe.StringData(extension)),
225221
C.int(len(extension)),
226222
)

core/src/ten_runtime/binding/go/interface/ten_runtime/msg.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,5 @@ ten_go_error_t ten_go_msg_get_name(uintptr_t bridge_addr, const char **name);
307307

308308
ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
309309
int app_uri_len, const void *graph_id,
310-
int graph_id_len,
311-
const void *extension_group,
312-
int extension_group_len,
313-
const void *extension, int extension_len);
310+
int graph_id_len, const void *extension,
311+
int extension_len);

core/src/ten_runtime/binding/go/native/msg/msg.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,8 @@ ten_go_error_t ten_go_msg_get_name(uintptr_t bridge_addr, const char **name) {
816816

817817
ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
818818
int app_uri_len, const void *graph_id,
819-
int graph_id_len,
820-
const void *extension_group,
821-
int extension_group_len,
822-
const void *extension, int extension_len) {
819+
int graph_id_len, const void *extension,
820+
int extension_len) {
823821
ten_go_msg_t *self = ten_go_msg_reinterpret(bridge_addr);
824822
TEN_ASSERT(self && ten_go_msg_check_integrity(self), "Should not happen.");
825823

@@ -832,10 +830,6 @@ ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
832830
ten_string_t graph_id_str;
833831
ten_string_init_from_c_str_with_size(&graph_id_str, graph_id, graph_id_len);
834832

835-
ten_string_t extension_group_str;
836-
ten_string_init_from_c_str_with_size(&extension_group_str, extension_group,
837-
extension_group_len);
838-
839833
ten_string_t extension_str;
840834
ten_string_init_from_c_str_with_size(&extension_str, extension,
841835
extension_len);
@@ -846,7 +840,6 @@ ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
846840
bool rc = ten_msg_clear_and_set_dest(
847841
ten_go_msg_c_msg(self), ten_string_get_raw_str(&app_uri_str),
848842
ten_string_get_raw_str(&graph_id_str),
849-
ten_string_get_raw_str(&extension_group_str),
850843
ten_string_get_raw_str(&extension_str), &err);
851844

852845
if (!rc) {
@@ -857,7 +850,6 @@ ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
857850
ten_error_deinit(&err);
858851
ten_string_deinit(&app_uri_str);
859852
ten_string_deinit(&graph_id_str);
860-
ten_string_deinit(&extension_group_str);
861853
ten_string_deinit(&extension_str);
862854

863855
return cgo_error;

core/src/ten_runtime/binding/nodejs/interface/msg/msg.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ export class Msg {
1414
setDest(
1515
appUri: string | undefined = undefined,
1616
graphId: string | undefined = undefined,
17-
extensionGroup: string | undefined = undefined,
1817
extension: string | undefined = undefined,
1918
) {
2019
ten_addon.ten_nodejs_msg_set_dest(
2120
this,
2221
appUri,
2322
graphId,
24-
extensionGroup,
2523
extension,
2624
);
2725
}

core/src/ten_runtime/binding/nodejs/native/msg/msg.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ static napi_value ten_nodejs_msg_get_name(napi_env env,
7373

7474
static napi_value ten_nodejs_msg_set_dest(napi_env env,
7575
napi_callback_info info) {
76-
const size_t argc = 5;
77-
napi_value args[argc]; // this, app_uri, graph_id, extension_group, extension
76+
const size_t argc = 4;
77+
napi_value args[argc]; // this, app_uri, graph_id, extension
7878
if (!ten_nodejs_get_js_func_args(env, info, args, argc)) {
7979
napi_fatal_error(NULL, NAPI_AUTO_LENGTH,
8080
"Incorrect number of parameters passed.",
@@ -98,9 +98,6 @@ static napi_value ten_nodejs_msg_set_dest(napi_env env,
9898
ten_string_t graph_id;
9999
TEN_STRING_INIT(graph_id);
100100

101-
ten_string_t extension_group;
102-
TEN_STRING_INIT(extension_group);
103-
104101
ten_string_t extension;
105102
TEN_STRING_INIT(extension);
106103

@@ -115,20 +112,14 @@ static napi_value ten_nodejs_msg_set_dest(napi_env env,
115112
}
116113

117114
if (!is_js_undefined(env, args[3])) {
118-
bool rc = ten_nodejs_get_str_from_js(env, args[3], &extension_group);
119-
RETURN_UNDEFINED_IF_NAPI_FAIL(rc, "Failed to get extension group", NULL);
120-
}
121-
122-
if (!is_js_undefined(env, args[4])) {
123-
bool rc = ten_nodejs_get_str_from_js(env, args[4], &extension);
115+
bool rc = ten_nodejs_get_str_from_js(env, args[3], &extension);
124116
RETURN_UNDEFINED_IF_NAPI_FAIL(rc, "Failed to get extension", NULL);
125117
}
126118

127119
bool rc = ten_msg_clear_and_set_dest(
128120
msg_bridge->msg, ten_string_get_raw_str(&app_uri),
129-
ten_string_get_raw_str(&graph_id),
130-
ten_string_get_raw_str(&extension_group),
131-
ten_string_get_raw_str(&extension), &err);
121+
ten_string_get_raw_str(&graph_id), ten_string_get_raw_str(&extension),
122+
&err);
132123
if (!rc) {
133124
ten_string_t code_str;
134125
ten_string_init_formatted(&code_str, "%d", ten_error_code(&err));
@@ -141,7 +132,6 @@ static napi_value ten_nodejs_msg_set_dest(napi_env env,
141132

142133
ten_string_deinit(&app_uri);
143134
ten_string_deinit(&graph_id);
144-
ten_string_deinit(&extension_group);
145135
ten_string_deinit(&extension);
146136
ten_error_deinit(&err);
147137

core/src/ten_runtime/binding/python/interface/ten_runtime/libten_runtime_python.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class _Msg:
2828
self,
2929
app_uri: Optional[str],
3030
graph_id: Optional[str],
31-
extension_group: Optional[str],
3231
extension: Optional[str],
3332
) -> None: ...
3433
def set_property_from_json(

0 commit comments

Comments
 (0)