rippled
Loading...
Searching...
No Matches
DNS_test.cpp
1#include <test/jtx.h>
2
3#include <xrpld/app/misc/detail/WorkSSL.h>
4
5#include <xrpl/basics/StringUtilities.h>
6
7#include <condition_variable>
8#include <memory>
9
10namespace xrpl {
11namespace test {
12
14{
15 using endpoint_type = boost::asio::ip::tcp::endpoint;
16 using error_code = boost::system::error_code;
25
26public:
27 DNS_test() : env_(*this)
28 {
29 }
30
31 void
32 makeRequest(endpoint_type const& lastEndpoint, bool lastStatus)
33 {
34 auto onFetch =
35 [&](error_code const& errorCode, endpoint_type const& endpoint, xrpl::detail::response_type&& resp) {
36 BEAST_EXPECT(!errorCode);
37 lastEndpoint_ = endpoint;
38 resolved_[endpoint.address().to_string()]++;
40 };
41
44 pUrl_.path,
45 port_,
48 env_.app().config(),
49 lastEndpoint,
50 lastStatus,
51 onFetch);
52 work_ = sp;
53 sp->run();
54
56 cv_.wait(l);
57 }
58
59 bool
61 {
62 using boost::asio::ip::tcp;
63 tcp::resolver resolver(env_.app().getIOContext());
64 std::string port = pUrl_.port ? std::to_string(*pUrl_.port) : "443";
65 auto results = resolver.resolve(pUrl_.domain, port);
66 auto it = results.begin();
67 auto end = results.end();
68 int n = 0;
69 for (; it != end; ++it)
70 ++n;
71 return n > 1;
72 }
73
74 void
76 {
77 std::string url = arg();
78 if (url == "")
79 url = "https://vl.ripple.com";
80 BEAST_EXPECT(parseUrl(pUrl_, url));
82 }
83
84 void
85 run() override
86 {
87 parse();
88 // First endpoint is random. Next three
89 // should resolve to the same endpoint. Run a few times
90 // to verify we are not selecting by chance the same endpoint.
91 for (int i = 1; i <= 4; ++i)
92 {
94 BEAST_EXPECT(resolved_.size() == 1 && resolved_.begin()->second == i);
95 }
97 return;
98 // Run with the "failed" status. In this case endpoints are selected at
99 // random but last endpoint is not selected.
101 for (int i = 0; i < 4; ++i)
103 // Should have more than one but some endpoints can repeat since
104 // selected at random. We'll never have four identical endpoints
105 // here because on failure we randomly select an endpoint different
106 // from the last endpoint.
107 BEAST_EXPECT(resolved_.size() > 1);
108 }
109};
110
111BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(DNS, app, xrpl, 20);
112
113} // namespace test
114} // namespace xrpl
T begin(T... args)
A testsuite class.
Definition suite.h:51
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:276
virtual Config & config()=0
virtual boost::asio::io_context & getIOContext()=0
virtual void run()=0
std::condition_variable cv_
Definition DNS_test.cpp:24
std::map< std::string, int > resolved_
Definition DNS_test.cpp:22
boost::asio::ip::tcp::endpoint endpoint_type
Definition DNS_test.cpp:15
std::string port_
Definition DNS_test.cpp:20
boost::system::error_code error_code
Definition DNS_test.cpp:16
void makeRequest(endpoint_type const &lastEndpoint, bool lastStatus)
Definition DNS_test.cpp:32
void run() override
Runs the suite.
Definition DNS_test.cpp:85
std::weak_ptr< xrpl::detail::Work > work_
Definition DNS_test.cpp:17
endpoint_type lastEndpoint_
Definition DNS_test.cpp:18
A transaction testing environment.
Definition Env.h:119
Application & app()
Definition Env.h:251
beast::Journal const journal
Definition Env.h:160
T clear(T... args)
T is_same_v
boost::beast::http::response< boost::beast::http::string_body > response_type
Definition Work.h:10
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool parseUrl(parsedURL &pUrl, std::string const &strUrl)
T size(T... args)
std::optional< std::uint16_t > port
T to_string(T... args)