message: Fix flakey websocket error handling test
diff: #include <external/json/json.hpp>
  #include <realm/util/base64.hpp>
  #include <realm/util/uri.hpp>
  +#include <realm/util/websocket.hpp>
  #include <thread>
  using namespace realm;
  @@ -2087,12 +2088,10 @@ TEST_CASE("app: sync integration", "[sync][app]") {
  auto config = setup_and_get_config(app);
  std::mutex sync_error_mutex;
  - util::Optional<SyncError> sync_error;
  + std::vector<SyncError> sync_errors;
  config.sync_config->error_handler = [&](auto, SyncError error) {
  std::lock_guard<std::mutex> lk(sync_error_mutex);
  - if (!sync_error) {
  - sync_error = error;
  - }
  + sync_errors.push_back(std::move(error));
  };
  auto r = realm::Realm::get_shared_realm(config);
  auto session = app->current_user()->session_for_on_disk_path(r->config().path);
  @@ -2111,15 +2110,28 @@ TEST_CASE("app: sync integration", "[sync][app]") {
  }
  r->commit_transaction();
  + const auto wait_start = std::chrono::steady_clock::now();
  + auto pred = [](const SyncError& error) {
  + return error.error_code.category() == util::websocket::websocket_close_status_category();
  + };
  util::EventLoop::main().run_until([&]() -> bool {
  std::lock_guard<std::mutex> lk(sync_error_mutex);
  - return static_cast<bool>(sync_error);
  + // If we haven't gotten an error in more than 2 minutes, then something has gone wrong
  + // and we should fail the test.
  + if (std::chrono::steady_clock::now() - wait_start > std::chrono::minutes(2)) {
  + return false;
  + }
  + return std::any_of(sync_errors.begin(), sync_errors.end(), pred);
  });
  auto captured_error = [&] {
  std::lock_guard<std::mutex> lk(sync_error_mutex);
  - return *sync_error;
  + const auto it = std::find_if(sync_errors.begin(), sync_errors.end(), pred);
  + REQUIRE(it != sync_errors.end());
  + return *it;
  }();
  +
  + REQUIRE(captured_error.error_code.category() == util::websocket::websocket_close_status_category());
  REQUIRE(captured_error.error_code.value() == 1009);
  REQUIRE(captured_error.message == "read limited at 16777217 bytes");
  }
  