015-resources.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Copyright (c) 2019-2020 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  3. //
  4. // Distributed under the MIT Software License
  5. //
  6. #include "access.h"
  7. #include "catch.hpp"
  8. #include "rotor.hpp"
  9. #include "supervisor_test.h"
  10. #include "actor_test.h"
  11. namespace r = rotor;
  12. namespace rt = r::test;
  13. TEST_CASE("release/aquire resources, when other actor is in progress of configuration", "[plugin]") {
  14. r::system_context_t system_context;
  15. auto sup = system_context.create_supervisor<rt::supervisor_test_t>()
  16. .timeout(rt::default_timeout)
  17. .create_registry(true)
  18. .finish();
  19. auto act = sup->create_actor<rt::actor_test_t>().timeout(rt::default_timeout).finish();
  20. act->configurer = [&](auto &, r::plugin::plugin_base_t &plugin) {
  21. plugin.with_casted<r::plugin::starter_plugin_t>([&](auto &) {
  22. auto res = act->access<rt::to::resources>();
  23. res->acquire(0);
  24. res->release(0);
  25. });
  26. };
  27. sup->do_process();
  28. CHECK(sup->get_state() == r::state_t::OPERATIONAL);
  29. CHECK(act->get_state() == r::state_t::OPERATIONAL);
  30. sup->do_shutdown();
  31. sup->do_process();
  32. CHECK(sup->get_state() == r::state_t::SHUT_DOWN);
  33. CHECK(act->get_state() == r::state_t::SHUT_DOWN);
  34. }