forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_common_test_base.h
77 lines (59 loc) · 2.58 KB
/
main_common_test_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include <string>
#include <vector>
#include "source/common/stats/isolated_store_impl.h"
#include "source/exe/main_common.h"
#include "test/test_common/environment.h"
#include "absl/synchronization/notification.h"
namespace Envoy {
class MainCommonTestBase {
protected:
MainCommonTestBase(Network::Address::IpVersion version);
const char* const* argv();
int argc();
// Adds an argument, assuring that argv remains null-terminated.
void addArg(const char* arg);
// Adds options to make Envoy exit immediately after initialization.
void initOnly();
std::string config_file_;
std::vector<const char*> argv_;
};
class AdminRequestTestBase : public MainCommonTestBase {
protected:
AdminRequestTestBase(Network::Address::IpVersion version);
// Runs an admin request specified in path, blocking until completion, and
// returning the response body.
std::string adminRequest(absl::string_view path, absl::string_view method);
// Initiates Envoy running in its own thread.
void startEnvoy();
// Conditionally pauses at a critical point in the Envoy thread, waiting for
// the test thread to trigger something at that exact line. The test thread
// can then call resume_.Notify() to allow the Envoy thread to resume.
void pauseResumeInterlock(bool enable);
// Wait until Envoy is inside the main server run loop proper. Before entering, Envoy runs any
// pending post callbacks, so it's not reliable to use adminRequest() or post() to do this.
// Generally, tests should not depend on this for correctness, but as a result of
// https://github.com/libevent/libevent/issues/779 we need to for TSAN. This is because the entry
// to event_base_loop() is where the signal base race occurs, but once we're in that loop in
// blocking mode, we're safe to take signals.
// TODO(htuch): Remove when https://github.com/libevent/libevent/issues/779 is fixed.
void waitForEnvoyRun();
// Having triggered Envoy to quit (via signal or /quitquitquit), this blocks until Envoy exits.
bool waitForEnvoyToExit();
// Sends a quit request to the server, and waits for Envoy to exit. Returns
// true if successful.
bool quitAndWait();
Stats::IsolatedStoreImpl stats_store_;
std::unique_ptr<Thread::Thread> envoy_thread_;
std::unique_ptr<MainCommon> main_common_;
absl::Notification started_;
absl::Notification finished_;
absl::Notification resume_;
absl::Notification pause_point_;
bool envoy_return_{false};
bool envoy_started_{false};
bool envoy_finished_{false};
bool pause_before_run_{false};
bool pause_after_run_{false};
};
} // namespace Envoy