Skip to content

Commit

Permalink
feat: add more test cases of failing to start graph
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Jan 9, 2025
1 parent 629bb0a commit f63480a
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_basic_1__predefined_graph,

} // namespace

TEST(ExtensionTest, PredefinedGraphBasic1) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphBasic1) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_basic_2__normal_extension,

} // namespace

TEST(ExtensionTest, PredefinedGraphBasic2) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphBasic2) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphEngineOwnEventloop) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphEngineOwnEventloop) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
102 changes: 102 additions & 0 deletions tests/ten_runtime/smoke/predefined_graph/predefined_graph_incorrect.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// Copyright © 2025 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.
//
#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
#include "tests/ten_runtime/smoke/util/binding/cpp/check.h"

namespace {

class test_predefined_graph : public ten::extension_t {
public:
explicit test_predefined_graph(const char *name) : ten::extension_t(name) {}

void on_cmd(ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_t> cmd) override {
nlohmann::json const detail = {{"id", 1}, {"name", "a"}};

auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
cmd_result->set_property_from_json("detail", detail.dump().c_str());
ten_env.return_result(std::move(cmd_result), std::move(cmd));
}
};

class test_app : public ten::app_t {
public:
void on_configure(ten::ten_env_t &ten_env) override {
bool rc = ten::ten_env_internal_accessor_t::init_manifest_from_json(
ten_env,
// clang-format off
R"({
"type": "app",
"name": "test_app",
"version": "0.1.0"
})"
// clang-format on
);
ASSERT_EQ(rc, true);

rc = ten_env.init_property_from_json(
// clang-format off
R"###({
"_ten": {
"uri": "msgpack://127.0.0.1:8001/",
"log_level": 2,
"predefined_graphs": [{
"name": "default",
"auto_start": true,
"singleton": true,
"nodes": [{
"type": "extension",
"name": "predefined_graph",
"addon": "predefined_graph_basic_1__predefined_graph",
"extension_group": "predefined_graph_group"
}]
}]
}
})###"
// clang-format on
);
ASSERT_EQ(rc, true);

ten_env.on_configure_done();
}
};

void *app_thread_main(TEN_UNUSED void *args) {
auto *app = new test_app();
app->run();
delete app;

return nullptr;
}

TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_basic_1__predefined_graph,
test_predefined_graph);

} // namespace

TEST(PredefinedGraphTest, PredefinedGraphBasic1) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/");

// Do not need to send 'start_graph' command first.
// The 'graph_id' MUST be "default" if we want to send the request to
// predefined graph.
auto test_cmd = ten::cmd_t::create("test");
test_cmd->set_dest("msgpack://127.0.0.1:8001/", "default",
"predefined_graph_group", "predefined_graph");
auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd));
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
ten_test::check_detail_with_json(cmd_result, R"({"id": 1, "name": "a"})");

delete client;

ten_thread_join(app_thread, -1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(predefined_graph_multi_app__extension_2,

} // namespace

TEST(ExtensionTest, PredefinedGraphMultiApp) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphMultiApp) { // NOLINT
// Start app.
auto *app_1_thread =
ten_thread_create("app thread 1", app_thread_1_main, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphMultiExtension1) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphMultiExtension1) { // NOLINT
// Start app.
auto *app_thread =
ten_thread_create("app thread", test_app_thread_main, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphMultiExtension2) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphMultiExtension2) { // NOLINT
// Start app.
auto *app_thread =
ten_thread_create("app thread", test_app_thread_main, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphMultiExtension3) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphMultiExtension3) { // NOLINT
// Start app.
auto *app_thread =
ten_thread_create("app thread", test_app_thread_main, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphMultiExtension4) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphMultiExtension4) { // NOLINT
// Start app.
auto *app_thread =
ten_thread_create("app thread", test_app_thread_main, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, PredefinedGraphNoAutoStart) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphNoAutoStart) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(prebuild_two_extensions_1,

} // namespace

TEST(ExtensionTest, PredefinedGraphTwoStandaloneExtensions1) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphTwoStandaloneExtensions1) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(prebuild_two_extensions_2,

} // namespace

TEST(ExtensionTest, PredefinedGraphTwoStandaloneExtensions2) { // NOLINT
TEST(PredefinedGraphTest, PredefinedGraphTwoStandaloneExtensions2) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, StartGraphAndCommunication) { // NOLINT
TEST(StartGraphTest, StartGraphAndCommunication) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, StartGraphFromExtension) { // NOLINT
TEST(StartGraphTest, StartGraphFromExtension) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(start_incorrect_graph_1__normal_extension,

} // namespace

TEST(ExtensionTest, StartIncorrectGraph1) { // NOLINT
TEST(StartGraphTest, StartIncorrectGraph1) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(start_incorrect_graph_2__normal_extension,

} // namespace

TEST(ExtensionTest, StartIncorrectGraph2) { // NOLINT
TEST(StartGraphTest, StartIncorrectGraph2) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, StartPredefinedGraphCrossApp) { // NOLINT
TEST(StartGraphTest, StartPredefinedGraphCrossApp) { // NOLINT
auto *app_1_thread =
ten_thread_create("app thread 1", app_thread_1_main, nullptr);
auto *app_2_thread =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, StartPredefinedGraphFromExtension) { // NOLINT
TEST(StartGraphTest, StartPredefinedGraphFromExtension) { // NOLINT
auto *app_thread = ten_thread_create("app thread", app_thread_main, nullptr);

// Create a client and connect to the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(

} // namespace

TEST(ExtensionTest, StartTwoPredefinedGraphs) { // NOLINT
TEST(StartGraphTest, StartTwoPredefinedGraphs) { // NOLINT
auto *app_1_thread =
ten_thread_create("app thread 1", app_thread_1_main, nullptr);
auto *app_2_thread =
Expand Down

0 comments on commit f63480a

Please sign in to comment.