| 232 | } |
| 233 | |
| 234 | int client(actor_system& sys, std::string_view mode, const std::string& host, |
| 235 | uint16_t port) { |
| 236 | auto& mm = sys.middleman(); |
| 237 | if (mode == "remote_actor") { |
| 238 | auto cell = with_retry([&] { return mm.remote_actor(host, port); }); |
| 239 | auto cell2 = mm.remote_actor(host, port); |
| 240 | if (!cell2 || *cell != *cell2) { |
| 241 | std::cout << "calling remote_actor twice must return the same handle\n"; |
| 242 | return EXIT_FAILURE; |
| 243 | } |
| 244 | return cell_tests(sys, *cell); |
| 245 | } |
| 246 | if (mode == "remote_spawn") { |
| 247 | auto nid = with_retry([&] { return mm.connect(host, port); }); |
| 248 | auto nid2 = mm.connect(host, port); // with cache |
| 249 | if (!nid2 || *nid != *nid2) { |
| 250 | std::cout << "calling connect twice must return the same node ID\n"; |
| 251 | return EXIT_FAILURE; |
| 252 | } |
| 253 | purge_cache(sys, host, port); |
| 254 | auto nid3 = mm.connect(host, port); // without cache |
| 255 | if (!nid3 || *nid != *nid3) { |
| 256 | std::cout << "calling connect twice must return the same node ID\n"; |
| 257 | return EXIT_FAILURE; |
| 258 | } |
| 259 | auto cell = mm.remote_spawn<actor>(*nid, "cell", make_message(int32_t{7}), |
| 260 | 5s); |
| 261 | if (!cell) { |
| 262 | std::cout << "remote spawn failed: " << to_string(cell.error()) << "\n"; |
| 263 | return EXIT_FAILURE; |
| 264 | } |
| 265 | return cell_tests(sys, *cell); |
| 266 | } |
| 267 | if (mode == "remote_lookup") { |
| 268 | auto nid = with_retry([&] { return mm.connect(host, port); }); |
| 269 | auto cell = mm.remote_lookup("cell", *nid); |
| 270 | if (!cell) { |
| 271 | std::cout << "remote_lookup failed\n"; |
| 272 | return EXIT_FAILURE; |
| 273 | } |
| 274 | return cell_tests(sys, actor_cast<actor>(cell)); |
| 275 | } |
| 276 | if (mode == "unpublish") { |
| 277 | auto ctrl = with_retry([&] { return mm.remote_actor(host, port); }); |
| 278 | bool unpublished = false; |
| 279 | scoped_actor self{sys}; |
| 280 | self->mail(ok_atom_v).request(*ctrl, 5s).receive( |
| 281 | [&unpublished] { unpublished = true; }, |
| 282 | [](const error& reason) { |
| 283 | std::cout << "failed to unpublish: " << to_string(reason) << "\n"; |
| 284 | }); |
| 285 | if (!unpublished) { |
| 286 | return EXIT_FAILURE; |
| 287 | } |
| 288 | with_retry([&] { |
| 289 | purge_cache(sys, host, port); |
| 290 | return !mm.remote_actor(host, port); |
| 291 | }); |
no test coverage detected