forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeepaliveTimerTest.cpp
More file actions
74 lines (51 loc) · 1.86 KB
/
KeepaliveTimerTest.cpp
File metadata and controls
74 lines (51 loc) · 1.86 KB
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
// Copyright 2004-present Facebook. All Rights Reserved.
#include <folly/ExceptionWrapper.h>
#include <folly/Format.h>
#include <folly/io/Cursor.h>
#include <folly/io/async/ScopedEventBaseThread.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "rsocket/framing/Frame.h"
#include "rsocket/framing/FramedDuplexConnection.h"
#include "rsocket/internal/KeepaliveTimer.h"
using namespace ::testing;
using namespace ::rsocket;
namespace {
class MockConnectionAutomaton : public FrameSink {
public:
// MOCK_METHOD doesn't take functions with unique_ptr args.
// A workaround for sendKeepalive method.
virtual void sendKeepalive(std::unique_ptr<folly::IOBuf> b) override {
sendKeepalive_(b);
}
MOCK_METHOD1(sendKeepalive_, void(std::unique_ptr<folly::IOBuf>&));
MOCK_METHOD1(disconnectOrCloseWithError_, void(Frame_ERROR&));
void disconnectOrCloseWithError(Frame_ERROR&& error) override {
disconnectOrCloseWithError_(error);
}
};
}
TEST(FollyKeepaliveTimerTest, StartStopWithResponse) {
auto connectionAutomaton =
std::make_shared<NiceMock<MockConnectionAutomaton>>();
EXPECT_CALL(*connectionAutomaton, sendKeepalive_(_)).Times(2);
folly::EventBase eventBase;
KeepaliveTimer timer(std::chrono::milliseconds(100), eventBase);
timer.start(connectionAutomaton);
timer.sendKeepalive();
timer.keepaliveReceived();
timer.sendKeepalive();
timer.stop();
}
TEST(FollyKeepaliveTimerTest, NoResponse) {
auto connectionAutomaton =
std::make_shared<StrictMock<MockConnectionAutomaton>>();
EXPECT_CALL(*connectionAutomaton, sendKeepalive_(_)).Times(1);
EXPECT_CALL(*connectionAutomaton, disconnectOrCloseWithError_(_)).Times(1);
folly::EventBase eventBase;
KeepaliveTimer timer(std::chrono::milliseconds(100), eventBase);
timer.start(connectionAutomaton);
timer.sendKeepalive();
timer.sendKeepalive();
timer.stop();
}