Skip to content

Commit

Permalink
Merge pull request #29 from AntelopeIO/gh-672-fix
Browse files Browse the repository at this point in the history
Undo previous change which causes `producer_plugin`  to exit early
  • Loading branch information
greg7mdp authored Jul 8, 2023
2 parents fa081b4 + 2d4538c commit 005d5a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 2 additions & 5 deletions include/appbase/application_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ class plugin : public abstract_plugin {
static_cast<Impl*>(this)->plugin_requires([&](auto& plug) { plug.startup(); });
app().plugin_started(this); // add to `running_plugins` before so it will be shutdown if we throw in `plugin_startup()`
static_cast<Impl*>(this)->plugin_startup();
if (app().is_quiting()) {
// some plugins, instead of throwing an exception when failing to start, call app().quit().
// throw exception to ensure no more plugin gets initialized, and all running plugins receive `plugin_shutdown()`
throw std::runtime_error("plugin " + name() + " quit during startup");
}
// some plugins (such as producer_plugin) may call `app().quit()` during startup (see `producer_plugin_impl::start_block()`.
// this is not cause for immediate termination.
}
assert(_state == started); // if initial state was not initialized, final state cannot be started
}
Expand Down
13 changes: 8 additions & 5 deletions tests/basic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ BOOST_AUTO_TEST_CASE(exception_in_startup)
}

// -----------------------------------------------------------------------------
// Here we make sure that if a plugin calls app().quit() during `plugin_startup()`
// plugin_shutdown is called for that plugin
// Here we make sure that if a plugin calls app().quit() during `plugin_startup()`,
// it doesn't interrupt the startup process for other plugins
// `producer_plugin` can do this and some tests like `terminate-scenarios-test-hard_replay`
// rely on other plugins getting initialized.
// -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(quit_in_startup)
{
Expand All @@ -397,10 +399,11 @@ BOOST_AUTO_TEST_CASE(quit_in_startup)
try {
app->startup();
} catch(const std::exception& e ) {
// appbase framework will throw an exception if app.quit() is called during startup
std::cout << "exception during startup (as expected): " << e.what() << "\n";
// appbase framework should *not* throw an exception if app.quit() is called during startup
BOOST_CHECK(false);
std::cout << "exception during startup: " << e.what() << "\n";
}
BOOST_CHECK(shutdown_counter == 1); // check that plugin_shutdown() was executed for pA
BOOST_CHECK(shutdown_counter == 0); // check that plugin_shutdown() was not executed for pA
} );

app_thread.join();
Expand Down

0 comments on commit 005d5a5

Please sign in to comment.