Skip to content

Commit

Permalink
Fix tests on gcc-13 & 14.
Browse files Browse the repository at this point in the history
Recent gcc versions are not getting any better handling multiple co_await's
and object initialization: when tried to enable CI for more recent compiler
versions (gcc-13 & gcc-14), I (again) stumbled upon a triggered assert
in AwaitableStateChecker. Rewrite this as a series of statements to work
around the bug.

Also while I'm here, fix format strings used in tests.
  • Loading branch information
dprokoptsev committed Jun 11, 2024
1 parent a97a5db commit cd5db85
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,36 @@ class TestEventLoop {

auto await_early_cancel() noexcept {
if constexpr (Cancellable) {
CORRAL_TRACE("sleep %p (%lld ms) early cancelling", this,
delay_.count());
CORRAL_TRACE("sleep %p (%ld ms) early cancelling", this,
delayMS());
return std::true_type{};
} else {
CORRAL_TRACE("sleep %p (%lld ms) NOT early cancelling", this,
delay_.count());
CORRAL_TRACE("sleep %p (%ld ms) NOT early cancelling", this,
delayMS());
return false;
}
}
bool await_ready() const noexcept { return false; }
void await_suspend(Handle h) {
CORRAL_TRACE(" ...on sleep %p (%lld ms)", this, delay_.count());
CORRAL_TRACE(" ...on sleep %p (%ld ms)", this, delayMS());
suspended_ = true;
parent_ = h;
it_ = eventLoop_.events_.emplace(eventLoop_.now_ + delay_, [this] {
CORRAL_TRACE("sleep %p (%lld ms) resuming parent", this,
delay_.count());
CORRAL_TRACE("sleep %p (%ld ms) resuming parent", this,
delayMS());
suspended_ = false;
parent_.resume();
});
}
auto await_cancel(Handle) noexcept {
if constexpr (Cancellable) {
CORRAL_TRACE("sleep %p (%lld ms) cancelling", this,
delay_.count());
CORRAL_TRACE("sleep %p (%ld ms) cancelling", this, delayMS());
eventLoop_.events_.erase(it_);
suspended_ = false;
return std::true_type{};
} else {
CORRAL_TRACE("sleep %p (%lld ms) NOT cancelling", this,
delay_.count());
CORRAL_TRACE("sleep %p (%ld ms) NOT cancelling", this,
delayMS());
return false;
}
}
Expand All @@ -142,6 +141,9 @@ class TestEventLoop {

void await_introspect(auto& c) const noexcept { c.node("Sleep"); }

private:
long delayMS() const { return static_cast<long>(delay_.count()); }

private:
TestEventLoop& eventLoop_;
milliseconds delay_;
Expand Down Expand Up @@ -1831,11 +1833,10 @@ CORRAL_TEST_CASE("bounded-channel") {
CATCH_CHECK(channel.full());
CATCH_CHECK(ranLast == false);

std::array<std::optional<int>, 3> values = {
co_await channel.receive(),
co_await channel.receive(),
co_await channel.receive(),
};
std::array<std::optional<int>, 3> values;
values[0] = co_await channel.receive();
values[1] = co_await channel.receive();
values[2] = co_await channel.receive();
CATCH_CHECK(values == std::array<std::optional<int>, 3>{1, 2, 3});

co_await yield;
Expand Down

0 comments on commit cd5db85

Please sign in to comment.