[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/LeeRuns/expresscpp/master/test/long_session.cpp [Back]  [Original]

#include "expresscpp/expresscpp.hpp"
#include "expresscpp/fetch.hpp"
#include "fmt/format.h"
#include "gtest/gtest.h"
#include "nlohmann/json.hpp"
#include "test_utils.hpp"

using namespace expresscpp;

constexpr uint16_t port = 8081;

TEST(LongSession, SleepSession) {
  ExpressCpp app;

  std::string error_message = "Internal Error";

  bool visited = false;
  app.Get("/users", [&](auto /*req*/, auto res, auto /*next*/) {
    visited = true;
    std::this_thread::sleep_for(std::chrono::seconds(5));
    res->Send("asdf");
  });

  app.Listen(port, [&](auto ec) {
    EXPECT_FALSE(ec);
    const auto should_work_response = fetch(fmt::format("localhost:{}/users", port));
    EXPECT_TRUE(visited);
  });
}

TEST(LongSession, LongResponsePayload) {
  ExpressCpp app;

  std::string error_message = "Internal Error";

  bool visited = false;
  app.Get("/users", [&](auto /*req*/, auto res, auto /*next*/) {
    visited = true;
    std::string s(500000, 'a');
    std::cout Send("ok");
  });

  app.Listen(port, [&](auto ec) {
    EXPECT_FALSE(ec);
    std::string s(size_of_payload, 'a');
    const FetchOptions op{ HttpMethod::Get,  {},  s};
    const auto should_work_response = fetch(fmt::format("localhost:{}/users", port), op);
  });
  EXPECT_TRUE(sleeper.Wait());
}

Web Proxy Viewer  |  New URL  |  Original Page