009-system-context.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "catch.hpp"
  7. #include "rotor.hpp"
  8. #include "supervisor_test.h"
  9. #include "system_context_test.h"
  10. namespace r = rotor;
  11. namespace rt = rotor::test;
  12. TEST_CASE("misconfigured root supervisor", "[system_context]") {
  13. rt::system_context_test_t system_context;
  14. auto sup = system_context.create_supervisor<rt::supervisor_test_t>().finish();
  15. REQUIRE(!sup);
  16. REQUIRE(system_context.reason->ec.value() == static_cast<int>(r::error_code_t::actor_misconfigured));
  17. REQUIRE(system_context.reason == system_context.reason->root());
  18. CHECK_THAT(system_context.reason->message(), Catch::EndsWith("actor is misconfigured"));
  19. REQUIRE(!system_context.get_supervisor());
  20. }
  21. TEST_CASE("properly configured root supervisor", "[system_context]") {
  22. rt::system_context_test_t system_context;
  23. auto sup = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  24. REQUIRE(sup);
  25. CHECK(!system_context.reason);
  26. CHECK(system_context.get_supervisor() == sup);
  27. sup->do_process();
  28. sup->do_shutdown();
  29. sup->do_process();
  30. sup.reset();
  31. }
  32. TEST_CASE("root supervisor cannot be created twice", "[system_context]") {
  33. rt::system_context_test_t system_context;
  34. auto sup1 = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  35. REQUIRE(sup1);
  36. REQUIRE(system_context.get_supervisor() == sup1);
  37. auto sup2 = system_context.create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  38. REQUIRE(!sup2);
  39. REQUIRE(system_context.get_supervisor() == sup1);
  40. REQUIRE(system_context.reason->ec.value() == static_cast<int>(r::error_code_t::supervisor_defined));
  41. CHECK_THAT(system_context.reason->message(), Catch::EndsWith("supervisor is already defined"));
  42. sup1->do_process();
  43. sup1->do_shutdown();
  44. sup1->do_process();
  45. }