Skip to content

Commit 6358fe1

Browse files
authored
chore: fix test_ci_asserts on windows nightlyRr/core 416 test assert nonzero exit code windows (#5696)
Resolves CORE-416. The `test_ci_asserts` unit test has been causing windows nightly runs to fail quite mysteriously as `ctest` would report all tests passing but still return an exit code of `-1` to the runner, failing the job. It turns out that when the `-V` (verbose) flag is used, `ctest` does some processing of the stdout/stderr of each unit test. Even if the tests succeed with an exit status of zero, certain patterns in the stdout or stderr can cause `ctest` to report failure anyway. One of those patterns seemingly is `internal error`, which is output by our `passert` failure. So, when `test_ci_asserts` would spawn a subprocess which intentionally fails asserts, `internal error` was printed to stderr and flagged by `ctest`, causing it to report failure. This pull request fixes that by capturing the output of the assertion-failing subprocess instead so it doesn't get reported to stdout. We also fix the new `passert` callback registration tests, whose failures we did not notice because they only failed in this nightly job. --- TYPE: NO_HISTORY DESC: Fix test_ci_asserts
1 parent 418ed7b commit 6358fe1

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

.github/workflows/nightly-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
if: contains(matrix.os, 'windows')
5858
working-directory: ${{ matrix.working_directory || github.workspace }}
5959
run: |
60-
cmake -B build -S $env:GITHUB_WORKSPACE -DTILEDB_WERROR=ON -DTILEDB_SERIALIZATION=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
60+
cmake -B build -S $env:GITHUB_WORKSPACE -DTILEDB_WERROR=ON -DTILEDB_SERIALIZATION=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DTILEDB_ASSERTIONS=${{ matrix.assertions }}
6161
6262
- name: Build TileDB
6363
working-directory: ${{ matrix.working_directory || github.workspace }}

test/ci/test_assert.cc

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,52 @@ TEST_CASE("CI: Test assertions configuration", "[ci][assertions]") {
6767
std::filesystem::temp_directory_path() / "try_assert.log";
6868
sprintf(
6969
command,
70-
"%s %s",
70+
"%s %s 2>&1",
7171
TILEDB_PATH_TO_TRY_ASSERT,
7272
try_assert_logfile.value().string().c_str());
7373
} else {
74-
sprintf(command, "%s", TILEDB_PATH_TO_TRY_ASSERT);
74+
sprintf(command, "%s 2>&1", TILEDB_PATH_TO_TRY_ASSERT);
7575
}
7676

77-
const int retval = system(command);
77+
#ifdef _WIN32
78+
FILE* sub = _popen(command, "r");
79+
#else
80+
FILE* sub = popen(command, "r");
81+
#endif
82+
REQUIRE(sub);
83+
84+
std::vector<std::string> sub_output;
85+
{
86+
char linebuf[1024];
87+
while (fgets(linebuf, sizeof(linebuf), sub) != nullptr) {
88+
sub_output.push_back(std::string(linebuf));
89+
}
90+
}
91+
#ifdef _WIN32
92+
const int retval = _pclose(sub);
93+
#else
94+
const int retval = pclose(sub);
95+
#endif
96+
97+
if (builtWithAssertions) {
98+
CHECK(sub_output.size() >= 2);
99+
if (sub_output.size() >= 1) {
100+
CAPTURE(sub_output[0]);
101+
CHECK(
102+
sub_output[0].find(
103+
"FATAL TileDB core library internal error: false") == 0);
104+
}
105+
if (sub_output.size() >= 2) {
106+
CAPTURE(sub_output[1]);
107+
CHECK(sub_output[1].find("try_assert.cc") != std::string::npos);
108+
}
109+
} else {
110+
CHECK(sub_output.size() == 1);
111+
if (sub_output.size() >= 1) {
112+
CAPTURE(sub_output[0]);
113+
CHECK(sub_output[0].find("Assert did not exit!") == 0);
114+
}
115+
}
78116

79117
// in case value is one not currently accepted, report what was returned.
80118
std::cout << "retval is " << retval << " (0x" << std::hex << retval
@@ -160,34 +198,54 @@ TEST_CASE("CI: passert callback registration non-FIFO", "[assertions]") {
160198
REQUIRE(order_.empty());
161199

162200
tiledb::common::passert_failure_run_callbacks();
163-
CHECK(order_ == std::vector<int>{10000, 100, 0});
201+
if (builtWithAssertions) {
202+
CHECK(order_ == std::vector<int>{10000, 100, 0});
203+
} else {
204+
CHECK(order_ == std::vector<int>{});
205+
}
164206
order_.clear();
165207

166208
tiledb::common::passert_failure_run_callbacks();
167-
CHECK(order_ == std::vector<int>{10001, 101, 1});
209+
if (builtWithAssertions) {
210+
CHECK(order_ == std::vector<int>{10001, 101, 1});
211+
} else {
212+
CHECK(order_ == std::vector<int>{});
213+
}
168214
order_.clear();
169215

170216
SECTION("Remove x") {
171217
inc_x.reset();
172218

173219
tiledb::common::passert_failure_run_callbacks();
174-
CHECK(order_ == std::vector<int>{10002, 102});
220+
if (builtWithAssertions) {
221+
CHECK(order_ == std::vector<int>{10002, 102});
222+
} else {
223+
CHECK(order_ == std::vector<int>{});
224+
}
175225
order_.clear();
176226
}
177227

178228
SECTION("Remove y") {
179229
inc_y.reset();
180230

181231
tiledb::common::passert_failure_run_callbacks();
182-
CHECK(order_ == std::vector<int>{10002, 2});
232+
if (builtWithAssertions) {
233+
CHECK(order_ == std::vector<int>{10002, 2});
234+
} else {
235+
CHECK(order_ == std::vector<int>{});
236+
}
183237
order_.clear();
184238
}
185239

186240
SECTION("Remove z") {
187241
inc_z.reset();
188242

189243
tiledb::common::passert_failure_run_callbacks();
190-
CHECK(order_ == std::vector<int>{102, 2});
244+
if (builtWithAssertions) {
245+
CHECK(order_ == std::vector<int>{102, 2});
246+
} else {
247+
CHECK(order_ == std::vector<int>{});
248+
}
191249
order_.clear();
192250
}
193251
}

0 commit comments

Comments
 (0)