Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: Build
# Build your program with clang
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: install clang-format
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: deps
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: deps
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake_modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: deps
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: deps
run: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/macosx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: Build
# Build all program
working-directory: ${{github.workspace}}
run: bazel build --define=ASYNC_SIMPLE_DISABLE_AIO=true ...
# googletest 1.17 triggers this warning in the Clang version on macos-latest.
run: bazel build --define=ASYNC_SIMPLE_DISABLE_AIO=true --cxxopt=-Wno-error=character-conversion ...

- name: Test
# Execute tests
working-directory: ${{github.workspace}}
run: bazel test --define=ASYNC_SIMPLE_DISABLE_AIO=true --test_output=errors ...
# Keep the warning visible without allowing an upstream header to fail the build.
run: bazel test --define=ASYNC_SIMPLE_DISABLE_AIO=true --cxxopt=-Wno-error=character-conversion --test_output=errors ...
build_with_cmake:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install
run: sudo apt-get install doxygen graphviz
- name: Checkout
uses: actions/checkout@v6
uses: actions/checkout@v7
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Yarn Install
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ jobs:
strategy:
matrix:
mode: [ Release ]
arch: [ x86 ]
arch: [ x64 ]

env:
CXX: cl.exe
CC: cl.exe

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: Generate Project
run: cmake -B Build/${{ matrix.mode }} -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DRFK_DEV=1 -G "Visual Studio 17 2022" -A x64
run: cmake -B Build/${{ matrix.mode }} -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DRFK_DEV=1 -A ${{ matrix.arch }}

- name: Build async_simple
run: cmake --build Build/${{ matrix.mode }} --config ${{ matrix.mode }} --verbose
Expand All @@ -42,12 +42,13 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: Build
working-directory: ${{github.workspace}}
run: bazel build ...
# Lazy.bench.cpp intentionally instantiates a coroutine chain 1000 levels deep.
run: bazel build --cxxopt=/templateDepth:2000 ...

- name: Test
working-directory: ${{github.workspace}}
run: bazel test --test_output=errors ...
run: bazel test --cxxopt=/templateDepth:2000 --test_output=errors ...
80 changes: 56 additions & 24 deletions async_simple/coro/test/LazyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,45 +303,42 @@ TEST_F(LazyTest, testYield) {
executors::SimpleExecutor executor(1);
std::mutex m1;
std::mutex m2;
int value1 = 0;
int value2 = 0;
m1.lock();
m2.lock();
std::atomic<int> value1 = 0;
std::atomic<int> value2 = 0;
std::unique_lock<std::mutex> gate1(m1);
std::unique_lock<std::mutex> gate2(m2);

auto test1 = [](std::mutex& m, int& value) -> Lazy<void> {
m.lock();
auto test1 = [](std::mutex& m, std::atomic<int>& value) -> Lazy<void> {
{ std::lock_guard<std::mutex> lock(m); }
// push task to queue's tail
co_await Yield();
value++;
co_return;
};

auto test2 = [](std::mutex& m, int& value) -> Lazy<void> {
m.lock();
auto test2 = [](std::mutex& m, std::atomic<int>& value) -> Lazy<void> {
{ std::lock_guard<std::mutex> lock(m); }
value++;
co_return;
};

test1(m1, value1).via(&executor).start([](Try<void> result) {});
std::this_thread::sleep_for(100000us);
ASSERT_EQ(0, value1);
ASSERT_EQ(0, value1.load());

test2(m2, value2).via(&executor).start([](Try<void> result) {});
std::this_thread::sleep_for(100000us);
ASSERT_EQ(0, value2);
ASSERT_EQ(0, value2.load());

m1.unlock();
gate1.unlock();
std::this_thread::sleep_for(100000us);
ASSERT_EQ(0, value1);
ASSERT_EQ(0, value2);
ASSERT_EQ(0, value1.load());
ASSERT_EQ(0, value2.load());

m2.unlock();
gate2.unlock();
std::this_thread::sleep_for(100000us);
ASSERT_EQ(1, value1);
ASSERT_EQ(1, value2);

m1.unlock();
m2.unlock();
ASSERT_EQ(1, value1.load());
ASSERT_EQ(1, value2.load());
}

TEST_F(LazyTest, testYieldCancel) {
Expand Down Expand Up @@ -2035,33 +2032,68 @@ TEST_F(LazyTest, testForbiddenCancel) {
{
auto signal = Signal::create();
async_simple::Promise<void> p;
auto lazy = [](async_simple::Future<void> f) -> Lazy<void> {
std::promise<void> ready;
std::promise<void> done;
auto readyFuture = ready.get_future();
auto doneFuture = done.get_future();
auto lazy = [](async_simple::Future<void> f,
std::promise<void>& ready) -> Lazy<void> {
auto slot = co_await CurrentSlot{};
EXPECT_NE(slot, nullptr);
co_await std::move(f);
ready.set_value();
try {
co_await std::move(f);
ADD_FAILURE() << "Expected cancellation to throw";
} catch (const async_simple::SignalException& e) {
EXPECT_EQ(e.value(), SignalType::Terminate);
}
EXPECT_TRUE(slot->canceled());
EXPECT_EQ(slot->signal()->state(), SignalType::Terminate);
};
lazy(p.getFuture()).setLazyLocal(signal.get()).via(&e).detach();
lazy(p.getFuture(), ready)
.setLazyLocal(signal.get())
.via(&e)
.start([&done](Try<void>&& result) {
EXPECT_FALSE(result.hasError());
done.set_value();
});
readyFuture.wait();
signal->emits(SignalType::Terminate);
auto status = doneFuture.wait_for(5s);
p.setValue();
if (status != std::future_status::ready) {
doneFuture.wait();
}
EXPECT_EQ(status, std::future_status::ready);
}
{
auto signal = Signal::create();
async_simple::Promise<void> p;
auto lazy = [](async_simple::Future<void> f) -> Lazy<void> {
std::promise<void> ready;
std::promise<void> done;
auto lazy = [](async_simple::Future<void> f,
std::promise<void>& ready) -> Lazy<void> {
auto slot = co_await CurrentSlot{};
EXPECT_NE(slot, nullptr);
co_await ForbidSignal{};
slot = co_await CurrentSlot{};
EXPECT_EQ(slot, nullptr);
ready.set_value();
co_await std::move(f);
slot = co_await CurrentSlot{};
EXPECT_EQ(slot, nullptr);
};
lazy(p.getFuture()).setLazyLocal(signal.get()).via(&e).detach();
lazy(p.getFuture(), ready)
.setLazyLocal(signal.get())
.via(&e)
.start([&done](Try<void>&& result) {
EXPECT_FALSE(result.hasError());
done.set_value();
});
ready.get_future().wait();
signal->emits(SignalType::Terminate);
p.setValue();
done.get_future().wait();
}
}

Expand Down
Loading