1
#pragma once
2

            
3
#include <chrono>
4
#include <list>
5
#include <string>
6

            
7
#include "envoy/data/core/v3/health_check_event.pb.h"
8
#include "envoy/data/core/v3/health_check_event.pb.validate.h" // IWYU pragma: keep
9

            
10
#include "test/test_common/utility.h"
11

            
12
#include "absl/base/thread_annotations.h"
13
#include "absl/synchronization/mutex.h"
14
#include "absl/types/optional.h"
15
#include "tests/uds_server.h"
16

            
17
namespace Envoy {
18

            
19
class HealthCheckSinkServer : public UDSServer {
20
public:
21
  HealthCheckSinkServer(const std::string path);
22
  ~HealthCheckSinkServer();
23

            
24
  void clear();
25
  absl::optional<envoy::data::core::v3::HealthCheckEvent>
26
  waitForEvent(std::chrono::milliseconds timeout = TestUtility::DefaultTimeout);
27

            
28
  template <typename P>
29
3
  bool expectEventTo(P&& pred, std::chrono::milliseconds timeout = TestUtility::DefaultTimeout) {
30
3
    auto maybe_event = waitForEvent(timeout);
31
3
    if (maybe_event.has_value()) {
32
3
      return pred(maybe_event.value());
33
3
    }
34
    return false;
35
3
  }
36

            
37
private:
38
  void msgCallback(const std::string& data);
39

            
40
  absl::Mutex mutex_;
41
  std::list<envoy::data::core::v3::HealthCheckEvent> events_ ABSL_GUARDED_BY(mutex_);
42
};
43

            
44
} // namespace Envoy