Skip to content

Commit b8fc48a

Browse files
authored
async test fixes and more debugability (#134)
1 parent fd80b91 commit b8fc48a

File tree

8 files changed

+107
-56
lines changed

8 files changed

+107
-56
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/checkout@v3
3131
- run: bazel test --config=ci //...
3232
- run: bazel test --config=ci //...
33-
workspace-directory: tests
33+
working-directory: tests
3434

3535
test-linux:
3636
runs-on: ubuntu-latest
@@ -44,7 +44,7 @@ jobs:
4444
- uses: actions/checkout@v3
4545
- run: bazel test --config=ci //...
4646
- run: bazel test --config=ci //...
47-
workspace-directory: tests
47+
working-directory: tests
4848

4949
check-module-headers:
5050
runs-on: ubuntu-latest

.vscode/launch.json

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,41 @@
1919
"preLaunchTask": "build //scripts:check_module_header"
2020
},
2121
{
22-
"name": "test @ecsact_runtime_serialize_test//:serialize",
22+
"name": "test @ecsact_runtime_tests//serialize",
2323
"request": "launch",
24-
"program": "${workspaceFolder}/tests/serialize/bazel-bin/serialize",
25-
"cwd": "${workspaceFolder}/tests/serialize",
26-
"args": [],
24+
"program": "${workspaceFolder}/tests/bazel-bin/serialize/serialize",
25+
"cwd": "${workspaceFolder}/tests",
26+
"args": [
27+
"--gtest_break_on_failure"
28+
],
29+
"type": "cppdbg",
30+
"windows": {
31+
"type": "cppvsdbg",
32+
"program": "${workspaceFolder}/tests/bazel-bin/serialize/serialize.exe",
33+
},
34+
"preLaunchTask": "build @ecsact_runtime_tests//serialize",
35+
"sourceFileMap": {
36+
"E:/.cache/bazel/output_base/execroot/ecsact_runtime_tests": "${workspaceFolder}/tests",
37+
"E:/.cache/bazel/output_base/execroot/ecsact_runtime": "${workspaceFolder}"
38+
}
39+
},
40+
{
41+
"name": "test @ecsact_runtime_tests//async",
42+
"request": "launch",
43+
"program": "${workspaceFolder}/tests/bazel-bin/async/async",
44+
"cwd": "${workspaceFolder}/tests",
45+
"args": [
46+
"--gtest_break_on_failure"
47+
],
2748
"type": "cppdbg",
2849
"windows": {
2950
"type": "cppvsdbg",
30-
"program": "${workspaceFolder}/tests/serialize/bazel-bin/serialize.exe",
51+
"program": "${workspaceFolder}/tests/bazel-bin/async/async.exe",
3152
},
32-
"preLaunchTask": "build @ecsact_runtime_serialize_test//:serialize",
53+
"preLaunchTask": "build @ecsact_runtime_tests//async",
3354
"sourceFileMap": {
34-
"C:/users/austin/_bazel_austin/7knza6r5/execroot/ecsact_runtime_serialize_test": "${workspaceFolder}/tests/serialize"
55+
"E:/.cache/bazel/output_base/execroot/ecsact_runtime_tests": "${workspaceFolder}/tests",
56+
"E:/.cache/bazel/output_base/execroot/ecsact_runtime": "${workspaceFolder}"
3557
}
3658
}
3759
]

.vscode/tasks.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@
2222
"group": "build"
2323
},
2424
{
25-
"label": "build @ecsact_runtime_serialize_test//:serialize",
25+
"label": "build @ecsact_runtime_tests//serialize",
2626
"command": "bazel",
2727
"type": "shell",
2828
"options": {
29-
"cwd": "${workspaceFolder}/tests/serialize"
29+
"cwd": "${workspaceFolder}/tests"
3030
},
3131
"args": [
3232
"build",
33-
"//:serialize"
33+
"//serialize"
34+
],
35+
"group": "build",
36+
"problemMatcher": []
37+
},
38+
{
39+
"label": "build @ecsact_runtime_tests//async",
40+
"command": "bazel",
41+
"type": "shell",
42+
"options": {
43+
"cwd": "${workspaceFolder}/tests"
44+
},
45+
"args": [
46+
"build",
47+
"//async"
3448
],
3549
"group": "build",
3650
"problemMatcher": []

WORKSPACE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ bazel_skylib_workspace()
1717

1818
http_archive(
1919
name = "ecsact_lang_cpp",
20-
sha256 = "e3d38870f79d43fd3f71b111100c4da88698e05fe1687e3d69856bcf2bc1fe1f",
21-
strip_prefix = "ecsact_lang_cpp-c88ffbca2e61834a31929330169cf4dcc0d18bcc",
22-
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/c88ffbca2e61834a31929330169cf4dcc0d18bcc.zip",
20+
sha256 = "2866569ed8d58f3e42b705bf38f77455fe9acf8ab2d1b05f611b847d4c291a67",
21+
strip_prefix = "ecsact_lang_cpp-b1fa28b445b98d5ba62ede19cd6a5bdfa51141be",
22+
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/b1fa28b445b98d5ba62ede19cd6a5bdfa51141be.zip",
2323
)
2424

2525
http_archive(

tests/.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/bazel-*
2-
/user.bazelrc
3-
/external
4-
/compile_commands.json
5-
/.cache/
1+
/bazel-*
2+
/user.bazelrc
3+
/external
4+
/compile_commands.json
5+
/.cache/

tests/WORKSPACE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ http_archive(
5151

5252
http_archive(
5353
name = "ecsact_lang_cpp",
54-
sha256 = "2eb4456d0a706952bd46cff9cb6d1353a70d981e69eb42939da65b4c019ec610",
55-
strip_prefix = "ecsact_lang_cpp-23cb4156fb69a3e7e54a1093a91cd63a87a8abb2",
56-
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/23cb4156fb69a3e7e54a1093a91cd63a87a8abb2.zip",
54+
sha256 = "2866569ed8d58f3e42b705bf38f77455fe9acf8ab2d1b05f611b847d4c291a67",
55+
strip_prefix = "ecsact_lang_cpp-b1fa28b445b98d5ba62ede19cd6a5bdfa51141be",
56+
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/b1fa28b445b98d5ba62ede19cd6a5bdfa51141be.zip",
5757
)
5858

5959
http_archive(

tests/async/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ ecsact_codegen(
2525

2626
cc_test(
2727
name = "async",
28-
copts = copts,
2928
srcs = [
3029
"async_ref_test.cc",
3130
":async_test_support_generated_headers",
31+
"@ecsact_runtime//reference/async_reference:async.cc",
3232
"@ecsact_runtime//reference/async_reference:async_reference.cc",
3333
"@ecsact_runtime//reference/async_reference:async_reference.hh",
34-
"@ecsact_runtime//reference/async_reference:async.cc",
3534
],
35+
copts = copts,
3636
deps = [
3737
":async_test_core_module_runtime",
38-
"@ecsact_runtime//:core",
38+
"@com_google_googletest//:gtest",
39+
"@com_google_googletest//:gtest_main",
3940
"@ecsact_runtime//:async",
41+
"@ecsact_runtime//:core",
4042
"@ecsact_runtime//:dynamic",
4143
"@ecsact_runtime//reference/async_reference:async",
42-
"@com_google_googletest//:gtest",
43-
"@com_google_googletest//:gtest_main",
4444
"@ecsact_runtime//reference/serialize_reference",
4545
],
4646
)

tests/async/async_ref_test.cc

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <array>
2-
#include <thread>
3-
#include <chrono>
42
#include <atomic>
3+
#include <chrono>
4+
#include <thread>
55

66
#include "gtest/gtest.h"
77

8-
#include "ecsact/runtime/async.h"
9-
#include "ecsact/runtime/dynamic.h"
108
#include "async_test.ecsact.hh"
119
#include "async_test.ecsact.systems.hh"
10+
#include "ecsact/runtime/async.h"
11+
#include "ecsact/runtime/dynamic.h"
1212

1313
using namespace std::chrono_literals;
1414
using std::chrono::duration_cast;
@@ -38,15 +38,41 @@ void assert_time_past(
3838
ASSERT_LT(time, time_to_assert);
3939
}
4040

41-
void assert_never_error(
41+
static bool _error_happened = false;
42+
43+
void assert_never_async_error(
4244
ecsact_async_error async_err,
4345
int request_ids_length,
4446
ecsact_async_request_id* request_ids,
4547
void* callback_user_data
4648
) {
47-
ASSERT_TRUE(false) << "Unexpected Ecsact Async Error";
49+
_error_happened = true;
50+
EXPECT_EQ(async_err, ECSACT_ASYNC_OK) //
51+
<< "Unexpected Ecsact Async Error";
52+
}
53+
54+
void assert_never_system_error(
55+
ecsact_execute_systems_error execute_err,
56+
void* callback_user_data
57+
) {
58+
_error_happened = true;
59+
EXPECT_EQ(execute_err, ECSACT_EXEC_SYS_OK) //
60+
<< "Unexpected Ecsact System Error";
4861
}
4962

63+
void flush_events_never_error(const ecsact_execution_events_collector* exec_evc
64+
) {
65+
_error_happened = false;
66+
auto async_evc = ecsact_async_events_collector{};
67+
async_evc.async_error_callback = &assert_never_async_error;
68+
async_evc.system_error_callback = &assert_never_system_error;
69+
ecsact_async_flush_events(exec_evc, &async_evc);
70+
}
71+
72+
#define FLUSH_EVENTS_NEVER_ERROR(exec_evc) \
73+
flush_events_never_error(exec_evc); \
74+
ASSERT_FALSE(_error_happened)
75+
5076
TEST(AsyncRef, ConnectBad) {
5177
auto connect_req_id = ecsact_async_connect("bad");
5278

@@ -471,7 +497,7 @@ TEST(AsyncRef, TryAction) {
471497

472498
ecsact_async_connect("good?tick_rate=25");
473499

474-
auto entity_request = ecsact_async_create_entity();
500+
static auto entity_request = ecsact_async_create_entity();
475501

476502
struct entity_cb_info {
477503
ecsact_entity_id entity;
@@ -486,16 +512,14 @@ TEST(AsyncRef, TryAction) {
486512
ecsact_async_request_id request_id,
487513
void* callback_user_data
488514
) {
489-
auto& entity_info = *static_cast<entity_cb_info*>(callback_user_data);
490-
491-
entity_info.wait = true;
492-
entity_info.entity = entity_id;
515+
cb_info.wait = true;
516+
cb_info.entity = entity_id;
517+
ASSERT_EQ(entity_request, request_id);
493518
};
494519

495520
ecsact_async_events_collector entity_async_evc{};
496521
entity_async_evc.async_entity_callback = entity_cb;
497-
entity_async_evc.async_entity_callback_user_data = &cb_info;
498-
entity_async_evc.async_error_callback = &assert_never_error;
522+
entity_async_evc.async_error_callback = &assert_never_async_error;
499523

500524
auto start_tick = ecsact_async_get_current_tick();
501525
while(cb_info.wait != true) {
@@ -505,29 +529,18 @@ TEST(AsyncRef, TryAction) {
505529
ASSERT_LT(tick_diff, 10);
506530
}
507531

508-
struct callback_info {
509-
bool wait = false;
510-
};
511-
512-
callback_info init_cb_info{};
513-
514532
// Prepare the events collector for the flush to make sure we got all the
515533
// events we expected.
534+
cb_info.wait = false;
516535
auto evc = ecsact_execution_events_collector{};
517-
evc.init_callback_user_data = &init_cb_info;
518536
evc.init_callback = //
519537
[](
520538
ecsact_event event,
521539
ecsact_entity_id entity_id,
522540
ecsact_component_id component_id,
523541
const void* component_data,
524542
void* callback_user_data
525-
) {
526-
auto wait_end = clock::now();
527-
auto& info = *static_cast<callback_info*>(callback_user_data);
528-
529-
info.wait = true;
530-
};
543+
) { cb_info.wait = true; };
531544

532545
// Declare components required for the action
533546
async_test::NeededComponent my_needed_component{};
@@ -561,7 +574,7 @@ TEST(AsyncRef, TryAction) {
561574

562575
start_tick = ecsact_async_get_current_tick();
563576
while(!cb_info.wait) {
564-
ecsact_async_flush_events(&evc, nullptr);
577+
FLUSH_EVENTS_NEVER_ERROR(&evc);
565578
auto current_tick = ecsact_async_get_current_tick();
566579
auto tick_diff = current_tick - start_tick;
567580
ASSERT_LT(tick_diff, 10);
@@ -572,6 +585,7 @@ TEST(AsyncRef, TryAction) {
572585
my_try_entity.my_entity = cb_info.entity;
573586

574587
// Declare an action, add a check to see it's running
588+
reached_system = false;
575589
ecsact_set_system_execution_impl(
576590
ecsact_id_cast<ecsact_system_like_id>(async_test::TryEntity::id),
577591
[](ecsact_system_execution_context* context) {
@@ -595,10 +609,11 @@ TEST(AsyncRef, TryAction) {
595609
options.actions = actions.data();
596610
options.actions_length = actions.size();
597611

598-
auto options_request = ecsact_async_enqueue_execution_options(options);
612+
ecsact_async_enqueue_execution_options(options);
599613

600614
start_tick = ecsact_async_get_current_tick();
601615
while(reached_system != true) {
616+
FLUSH_EVENTS_NEVER_ERROR(nullptr);
602617
auto current_tick = ecsact_async_get_current_tick();
603618
auto tick_diff = current_tick - start_tick;
604619
ASSERT_LT(tick_diff, 10);

0 commit comments

Comments
 (0)