Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed Nov 2, 2023
1 parent e733106 commit ce7d371
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
1 change: 1 addition & 0 deletions python/mrc/_pymrc/include/pymrc/asyncio_runnable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void AsyncioRunnable<InputT, OutputT>::run(mrc::runnable::Context& ctx)
LOG(INFO) << "AsyncioRunnable::run() > Calling run_until_complete() on main_task()";

loop.attr("run_until_complete")(std::move(py_awaitable));
loop.attr("close")();
}

// Need to drop the output edges
Expand Down
41 changes: 6 additions & 35 deletions python/mrc/_pymrc/tests/test_asyncio_runnable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include "test_pymrc.hpp"
#include "pymrc/asyncio_runnable.hpp"
#include "pymrc/coro.hpp"
#include "pymrc/executor.hpp"
Expand All @@ -37,6 +38,8 @@
#include <boost/fiber/policy.hpp>
#include <gtest/gtest.h>
#include <pybind11/cast.h>
#include <chrono>
#include <functional>
#include <pybind11/embed.h>
#include <pybind11/eval.h>
#include <pybind11/gil.h>
Expand All @@ -57,41 +60,7 @@ namespace pymrc = mrc::pymrc;
using namespace std::string_literals;
using namespace py::literals;

class TestWithPythonInterpreter : public ::testing::Test
{
public:
virtual void interpreter_setup() = 0;

protected:
void SetUp() override;

void TearDown() override;

private:
static bool m_initialized;
};

bool TestWithPythonInterpreter::m_initialized;

void TestWithPythonInterpreter::SetUp()
{
if (!m_initialized)
{
m_initialized = true;
pybind11::initialize_interpreter();
interpreter_setup();
}
}

void TestWithPythonInterpreter::TearDown() {}

class __attribute__((visibility("default"))) TestAsyncioRunnable : public TestWithPythonInterpreter
{
void interpreter_setup() override
{
pybind11::module_::import("mrc.core.coro");
}
};
PYMRC_TEST_CLASS(AsyncioRunnable);

class PythonCallbackAsyncioRunnable : public pymrc::AsyncioRunnable<int, int>
{
Expand Down Expand Up @@ -124,6 +93,8 @@ class PythonCallbackAsyncioRunnable : public pymrc::AsyncioRunnable<int, int>

TEST_F(TestAsyncioRunnable, UseAsyncioTasks)
{
pybind11::module_::import("mrc.core.coro");

py::object globals = py::globals();
py::exec(
R"(
Expand Down

0 comments on commit ce7d371

Please sign in to comment.