009-system-context.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Copyright (c) 2019-2021 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  3. //
  4. // Distributed under the MIT Software License
  5. //
  6. #include "rotor.hpp"
  7. #include "supervisor_test.h"
  8. #include "system_context_test.h"
  9. #include <catch2/matchers/catch_matchers.hpp>
  10. #include <catch2/matchers/catch_matchers_string.hpp>
  11. namespace r = rotor;
  12. namespace rt = rotor::test;
  13. TEST_CASE("misconfigured root supervisor", "[system_context]") {
  14. rt::system_context_test_t system_context;
  15. auto sup = system_context.create_supervisor<rt::supervisor_test_t>().finish();
  16. REQUIRE(!sup);
  17. REQUIRE(system_context.reason->ec.value() == static_cast<int>(r::error_code_t::actor_misconfigured));
  18. REQUIRE(system_context.reason == system_context.reason->root());
  19. CHECK_THAT(system_context.reason->message(), Catch::Matchers::EndsWith("actor is misconfigured"));
  20. REQUIRE(!system_context.get_supervisor());
  21. }
  22. TEST_CASE("properly configured root supervisor", "[system_context]") {
  23. rt::system_context_test_t system_context;
  24. auto sup = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  25. REQUIRE(sup);
  26. CHECK(!system_context.reason);
  27. CHECK(system_context.get_supervisor() == sup);
  28. sup->do_process();
  29. sup->do_shutdown();
  30. sup->do_process();
  31. sup.reset();
  32. }
  33. TEST_CASE("root supervisor cannot be created twice", "[system_context]") {
  34. rt::system_context_test_t system_context;
  35. auto sup1 = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  36. REQUIRE(sup1);
  37. REQUIRE(system_context.get_supervisor() == sup1);
  38. auto sup2 = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  39. REQUIRE(!sup2);
  40. REQUIRE(system_context.get_supervisor() == sup1);
  41. REQUIRE(system_context.reason->ec.value() == static_cast<int>(r::error_code_t::supervisor_defined));
  42. CHECK_THAT(system_context.reason->message(), Catch::Matchers::EndsWith("supervisor is already defined"));
  43. sup1->do_process();
  44. sup1->do_shutdown();
  45. sup1->do_process();
  46. }