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 ripple {
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 = [&](error_code const& errorCode,
35 endpoint_type const& endpoint,
37 BEAST_EXPECT(!errorCode);
38 lastEndpoint_ = endpoint;
39 resolved_[endpoint.address().to_string()]++;
41 };
42
45 pUrl_.path,
46 port_,
49 env_.app().config(),
50 lastEndpoint,
51 lastStatus,
52 onFetch);
53 work_ = sp;
54 sp->run();
55
57 cv_.wait(l);
58 }
59
60 bool
62 {
63 using boost::asio::ip::tcp;
64 tcp::resolver resolver(env_.app().getIOContext());
65 std::string port = pUrl_.port ? std::to_string(*pUrl_.port) : "443";
66 auto results = resolver.resolve(pUrl_.domain, port);
67 auto it = results.begin();
68 auto end = results.end();
69 int n = 0;
70 for (; it != end; ++it)
71 ++n;
72 return n > 1;
73 }
74
75 void
77 {
78 std::string url = arg();
79 if (url == "")
80 url = "https://vl.ripple.com";
81 BEAST_EXPECT(parseUrl(pUrl_, url));
83 }
84
85 void
86 run() override
87 {
88 parse();
89 // First endpoint is random. Next three
90 // should resolve to the same endpoint. Run a few times
91 // to verify we are not selecting by chance the same endpoint.
92 for (int i = 1; i <= 4; ++i)
93 {
95 BEAST_EXPECT(
96 resolved_.size() == 1 && resolved_.begin()->second == i);
97 }
99 return;
100 // Run with the "failed" status. In this case endpoints are selected at
101 // random but last endpoint is not selected.
103 for (int i = 0; i < 4; ++i)
105 // Should have more than one but some endpoints can repeat since
106 // selected at random. We'll never have four identical endpoints
107 // here because on failure we randomly select an endpoint different
108 // from the last endpoint.
109 BEAST_EXPECT(resolved_.size() > 1);
110 }
111};
112
113BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(DNS, app, ripple, 20);
114
115} // namespace test
116} // namespace ripple
T begin(T... args)
A testsuite class.
Definition suite.h:52
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:285
virtual Config & config()=0
virtual boost::asio::io_context & getIOContext()=0
virtual void run()=0
std::weak_ptr< ripple::detail::Work > work_
Definition DNS_test.cpp:17
void makeRequest(endpoint_type const &lastEndpoint, bool lastStatus)
Definition DNS_test.cpp:32
void run() override
Runs the suite.
Definition DNS_test.cpp:86
std::map< std::string, int > resolved_
Definition DNS_test.cpp:22
boost::asio::ip::tcp::endpoint endpoint_type
Definition DNS_test.cpp:15
endpoint_type lastEndpoint_
Definition DNS_test.cpp:18
boost::system::error_code error_code
Definition DNS_test.cpp:16
std::condition_variable cv_
Definition DNS_test.cpp:24
A transaction testing environment.
Definition Env.h:102
Application & app()
Definition Env.h:242
beast::Journal const journal
Definition Env.h:143
T clear(T... args)
T is_same_v
boost::beast::http::response< boost::beast::http::string_body > response_type
Definition Work.h:12
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool parseUrl(parsedURL &pUrl, std::string const &strUrl)
T size(T... args)
std::optional< std::uint16_t > port
T to_string(T... args)