proxygen
HTTPTransactionSMTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
13 
14 using namespace proxygen;
15 
17  public:
19  HTTPTransactionEgressSM::getNewInstance()) {}
20 
23  }
24 
27  }
28  private:
30 };
31 
33  public:
35  instance_(HTTPTransactionIngressSM::getNewInstance()) {}
36 
39  }
40 
43  }
44  private:
46 };
47 
48 // Egress tests
49 
50 TEST_F(EgressStateMachineFixture, BadEgressTransitions1) {
51  follow(HTTPTransactionEgressSM::Event::sendHeaders);
52  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
53  follow(HTTPTransactionEgressSM::Event::sendBody);
54  fail(HTTPTransactionEgressSM::Event::sendEOM);
55 }
56 
57 TEST_F(EgressStateMachineFixture, BadEgressTransitions2) {
58  fail(HTTPTransactionEgressSM::Event::sendBody);
59 }
60 
61 TEST_F(EgressStateMachineFixture, BadEgressTransitions3) {
62  follow(HTTPTransactionEgressSM::Event::sendHeaders);
63  follow(HTTPTransactionEgressSM::Event::sendBody);
64  follow(HTTPTransactionEgressSM::Event::sendBody);
65  follow(HTTPTransactionEgressSM::Event::sendEOM);
66  fail(HTTPTransactionEgressSM::Event::sendEOM);
67 }
68 
69 TEST_F(EgressStateMachineFixture, BadEgressTransitions4) {
70  follow(HTTPTransactionEgressSM::Event::sendHeaders);
71  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
72  follow(HTTPTransactionEgressSM::Event::sendBody);
73  follow(HTTPTransactionEgressSM::Event::sendChunkTerminator);
74  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
75  fail(HTTPTransactionEgressSM::Event::sendChunkTerminator);
76 }
77 
78 TEST_F(EgressStateMachineFixture, EgressChunkedTransitions) {
79  follow(HTTPTransactionEgressSM::Event::sendHeaders);
80 
81  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
82  follow(HTTPTransactionEgressSM::Event::sendBody);
83  follow(HTTPTransactionEgressSM::Event::sendChunkTerminator);
84 
85  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
86  follow(HTTPTransactionEgressSM::Event::sendBody);
87  follow(HTTPTransactionEgressSM::Event::sendChunkTerminator);
88 
89  follow(HTTPTransactionEgressSM::Event::sendChunkHeader);
90  follow(HTTPTransactionEgressSM::Event::sendBody);
91  follow(HTTPTransactionEgressSM::Event::sendChunkTerminator);
92 
93  follow(HTTPTransactionEgressSM::Event::sendTrailers);
94 
95  follow(HTTPTransactionEgressSM::Event::sendEOM);
96  follow(HTTPTransactionEgressSM::Event::eomFlushed);
97 }
98 
99 TEST_F(EgressStateMachineFixture, NormalEgressTransitions) {
100  follow(HTTPTransactionEgressSM::Event::sendHeaders);
101  follow(HTTPTransactionEgressSM::Event::sendBody);
102  follow(HTTPTransactionEgressSM::Event::sendBody);
103  follow(HTTPTransactionEgressSM::Event::sendBody);
104  follow(HTTPTransactionEgressSM::Event::sendBody);
105  follow(HTTPTransactionEgressSM::Event::sendEOM);
106 }
107 
108 TEST_F(EgressStateMachineFixture, NormalEgressTransitionsWithTrailers) {
109  follow(HTTPTransactionEgressSM::Event::sendHeaders);
110  follow(HTTPTransactionEgressSM::Event::sendBody);
111  follow(HTTPTransactionEgressSM::Event::sendBody);
112  follow(HTTPTransactionEgressSM::Event::sendBody);
113  follow(HTTPTransactionEgressSM::Event::sendBody);
114  follow(HTTPTransactionEgressSM::Event::sendTrailers);
115  follow(HTTPTransactionEgressSM::Event::sendEOM);
116  follow(HTTPTransactionEgressSM::Event::eomFlushed);
117 }
118 
119 TEST_F(EgressStateMachineFixture, WeirdEgressTransitions) {
120  follow(HTTPTransactionEgressSM::Event::sendHeaders);
121  follow(HTTPTransactionEgressSM::Event::sendTrailers);
122  follow(HTTPTransactionEgressSM::Event::sendEOM);
123  follow(HTTPTransactionEgressSM::Event::eomFlushed);
124 }
125 
126 // Ingress tests
127 
128 TEST_F(IngressStateMachineFixture, BadIngressTransitions1) {
129  follow(HTTPTransactionIngressSM::Event::onHeaders);
130  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
131  follow(HTTPTransactionIngressSM::Event::onBody);
132  fail(HTTPTransactionIngressSM::Event::onEOM);
133 }
134 
135 TEST_F(IngressStateMachineFixture, BadIngressTransitions2) {
136  fail(HTTPTransactionIngressSM::Event::onBody);
137 }
138 
139 TEST_F(IngressStateMachineFixture, BadIngressTransitions3) {
140  follow(HTTPTransactionIngressSM::Event::onHeaders);
141  follow(HTTPTransactionIngressSM::Event::onBody);
142  follow(HTTPTransactionIngressSM::Event::onBody);
143  follow(HTTPTransactionIngressSM::Event::onEOM);
144  fail(HTTPTransactionIngressSM::Event::onEOM);
145 }
146 
147 TEST_F(IngressStateMachineFixture, BadIngressTransitions4) {
148  follow(HTTPTransactionIngressSM::Event::onHeaders);
149  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
150  follow(HTTPTransactionIngressSM::Event::onBody);
151  follow(HTTPTransactionIngressSM::Event::onChunkComplete);
152  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
153  fail(HTTPTransactionIngressSM::Event::onChunkComplete);
154 }
155 
156 TEST_F(IngressStateMachineFixture, IngressChunkedTransitions) {
157  follow(HTTPTransactionIngressSM::Event::onHeaders);
158 
159  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
160  follow(HTTPTransactionIngressSM::Event::onBody);
161  follow(HTTPTransactionIngressSM::Event::onChunkComplete);
162 
163  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
164  follow(HTTPTransactionIngressSM::Event::onBody);
165  follow(HTTPTransactionIngressSM::Event::onChunkComplete);
166 
167  follow(HTTPTransactionIngressSM::Event::onChunkHeader);
168  follow(HTTPTransactionIngressSM::Event::onBody);
169  follow(HTTPTransactionIngressSM::Event::onChunkComplete);
170 
171  follow(HTTPTransactionIngressSM::Event::onTrailers);
172  follow(HTTPTransactionIngressSM::Event::onEOM);
173 }
174 
175 TEST_F(IngressStateMachineFixture, NormalIngressTransitions) {
176  follow(HTTPTransactionIngressSM::Event::onHeaders);
177  follow(HTTPTransactionIngressSM::Event::onBody);
178  follow(HTTPTransactionIngressSM::Event::onBody);
179  follow(HTTPTransactionIngressSM::Event::onBody);
180  follow(HTTPTransactionIngressSM::Event::onBody);
181  follow(HTTPTransactionIngressSM::Event::onEOM);
182 }
183 
184 TEST_F(IngressStateMachineFixture, WeirdIngressTransitions) {
185  follow(HTTPTransactionIngressSM::Event::onHeaders);
186  follow(HTTPTransactionIngressSM::Event::onTrailers);
187  follow(HTTPTransactionIngressSM::Event::onEOM);
188 }
typename T::State State
Definition: StateMachine.h:20
void follow(HTTPTransactionEgressSM::Event e)
void fail(HTTPTransactionIngressSM::Event e)
void fail(HTTPTransactionEgressSM::Event e)
static bool transit(State &state, Event event)
Definition: StateMachine.h:27
void fail()
HTTPTransactionEgressSM::State instance_
HTTPTransactionIngressSM::State instance_
typename T::Event Event
Definition: StateMachine.h:21
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST_F(HeaderTableTests, IndexTranslation)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void follow(HTTPTransactionIngressSM::Event e)