fixture.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // SPDX-FileCopyrightText: 2019-2022 Ivan Baidakou
  3. #include "fixture.h"
  4. #include "test-utils.h"
  5. #include "sample_db.h"
  6. #include "net/names.h"
  7. #include "access.h"
  8. #include "hasher/hasher_actor.h"
  9. #include "hasher/hasher_proxy_actor.h"
  10. #include "catch.hpp"
  11. using namespace syncspirit::test;
  12. using namespace syncspirit::model;
  13. using namespace syncspirit::net;
  14. Fixture::Fixture() { utils::set_default("trace"); }
  15. void Fixture::run() {
  16. root_path = bfs::unique_path();
  17. bfs::create_directory(root_path);
  18. auto root_path_guard = path_guard_t(root_path);
  19. std::uint64_t key = 0;
  20. db::Device db_my;
  21. db_my.set_id(test::device_id2sha256("KHQNO2S-5QSILRK-YX4JZZ4-7L77APM-QNVGZJT-EKU7IFI-PNEPBMY-4MXFMQD"));
  22. db_my.set_name("d1");
  23. db_my.set_cert_name("d1_cert_name");
  24. device_my = model::device_ptr_t(new model::device_t(db_my, ++key));
  25. db::Device db_peer;
  26. db_peer.set_id(test::device_id2sha256("KUEQE66-JJ7P6AD-BEHD4ZW-GPBNW6Q-Y4C3K4Y-X44WJWZ-DVPIDXS-UDRJMA7"));
  27. db_peer.set_name("d2");
  28. db_peer.set_cert_name("d2_cert_name");
  29. device_peer = model::device_ptr_t(new model::device_t(db_peer, ++key));
  30. cluster = new cluster_t(device_my);
  31. setup();
  32. r::system_context_t ctx;
  33. auto timeout = r::pt::milliseconds{10};
  34. sup = ctx.create_supervisor<supervisor_t>().timeout(timeout).create_registry().finish();
  35. sup->start();
  36. sup->create_actor<fs::file_actor_t>().timeout(timeout).finish();
  37. sup->create_actor<hasher::hasher_actor_t>().index(1).timeout(timeout).finish();
  38. sup->create_actor<hasher::hasher_proxy_actor_t>()
  39. .hasher_threads(1)
  40. .name(names::hasher_proxy)
  41. .timeout(timeout)
  42. .finish();
  43. sup->create_actor<sample_db_t>().timeout(timeout).finish();
  44. peer = sup->create_actor<sample_peer_t>().timeout(timeout).finish();
  45. pre_run();
  46. sup->do_process();
  47. create_controller();
  48. main();
  49. sup->shutdown();
  50. sup->do_process();
  51. CHECK(controller->access<to::state>() == r::state_t::SHUT_DOWN);
  52. CHECK(peer->access<to::state>() == r::state_t::SHUT_DOWN);
  53. }
  54. void Fixture::create_controller() {
  55. auto bep_config = config::bep_config_t();
  56. bep_config.rx_buff_size = 1024;
  57. auto timeout = r::pt::milliseconds{10};
  58. controller = sup->create_actor<controller_actor_t>()
  59. .cluster(cluster)
  60. .device(device_my)
  61. .peer_addr(peer->get_address())
  62. .peer(device_peer)
  63. .request_timeout(timeout)
  64. .peer_cluster_config(std::move(peer_cluster_config))
  65. .ignored_folders(&ignored_folders)
  66. .bep_config(bep_config)
  67. .timeout(timeout)
  68. .finish();
  69. sup->do_process();
  70. auto reason = controller->get_shutdown_reason();
  71. if (reason) {
  72. spdlog::warn("shutdown reason = {}", reason->message());
  73. };
  74. REQUIRE(!reason);
  75. }
  76. void Fixture::setup() {}
  77. void Fixture::pre_run() {}
  78. void Fixture::main() {}