File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
#include < compat.h>
6
6
#include < test/util/setup_common.h>
7
+ #include < threadinterrupt.h>
7
8
#include < util/sock.h>
8
9
#include < util/system.h>
9
10
10
11
#include < boost/test/unit_test.hpp>
11
12
13
+ #include < cassert>
12
14
#include < thread>
13
15
14
16
using namespace std ::chrono_literals;
@@ -144,6 +146,35 @@ BOOST_AUTO_TEST_CASE(wait)
144
146
waiter.join ();
145
147
}
146
148
149
+ BOOST_AUTO_TEST_CASE (recv_until_terminator_limit)
150
+ {
151
+ constexpr auto timeout = 1min; // High enough so that it is never hit.
152
+ CThreadInterrupt interrupt;
153
+ int s[2 ];
154
+ CreateSocketPair (s);
155
+
156
+ Sock sock_send (s[0 ]);
157
+ Sock sock_recv (s[1 ]);
158
+
159
+ std::thread receiver ([&sock_recv, &timeout, &interrupt]() {
160
+ constexpr size_t max_data{10 };
161
+ bool threw_as_expected{false };
162
+ // BOOST_CHECK_EXCEPTION() writes to some variables shared with the main thread which
163
+ // creates a data race. So mimic it manually.
164
+ try {
165
+ sock_recv.RecvUntilTerminator (' \n ' , timeout, interrupt, max_data);
166
+ } catch (const std::runtime_error& e) {
167
+ threw_as_expected = HasReason (" too many bytes without a terminator" )(e);
168
+ }
169
+ assert (threw_as_expected);
170
+ });
171
+
172
+ BOOST_REQUIRE_NO_THROW (sock_send.SendComplete (" 1234567" , timeout, interrupt));
173
+ BOOST_REQUIRE_NO_THROW (sock_send.SendComplete (" 89a\n " , timeout, interrupt));
174
+
175
+ receiver.join ();
176
+ }
177
+
147
178
#endif /* WIN32 */
148
179
149
180
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments