Skip to content

Commit 1823aa8

Browse files
committed
testing changes
1 parent 0fc6ac3 commit 1823aa8

2 files changed

Lines changed: 70 additions & 31 deletions

File tree

include/boost/beast2/impl/body_write_stream.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class body_write_stream_op : public asio::coroutine
102102
{
103103
boost::ignore_unused(bytes_transferred);
104104

105-
std::cout << ec.message() << std::endl;
106-
107105
BOOST_ASIO_CORO_REENTER(*this)
108106
{
109107
self.reset_cancellation_state(asio::enable_total_cancellation());

test/unit/body_write_stream.cpp

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,22 @@ struct single_tester : public ctx_base
237237

238238
struct chunking_handler
239239
{
240-
std::size_t n_;
241240
system::error_code ec_;
242-
std::size_t* total_;
243-
boost::buffers::string_buffer* buf_;
241+
std::size_t* written_;
244242

245243
chunking_handler(
246-
std::size_t n,
247244
system::error_code ec,
248-
std::size_t* total,
249-
boost::buffers::string_buffer* buf = nullptr)
250-
: n_(n)
251-
, ec_(ec)
252-
, total_(total)
253-
, buf_(buf)
245+
std::size_t* written)
246+
: ec_(ec)
247+
, written_(written)
254248
{
255249
}
256250

257251
void
258252
operator()(system::error_code ec, std::size_t n)
259253
{
260254
BOOST_TEST_EQ(ec, ec_);
261-
BOOST_TEST_EQ(n, n_);
262-
if(buf_)
263-
buf_->commit(n);
264-
*total_ += n;
255+
*written_ += n;
265256
}
266257
};
267258

@@ -280,33 +271,82 @@ struct single_tester : public ctx_base
280271
{
281272
wts_.write_size(cs); // Limit und stream write size to cs
282273

274+
std::string finals;
275+
finals.reserve(bs * iters);
276+
283277
std::size_t total = 0;
278+
std::size_t prev = 0;
284279
for(int i = 0; i < iters; i++)
285280
{
286-
auto cb = make_test_buffer(bs);
281+
std::string val = body_.substr(0, bs);
282+
val.resize(bs, '.');
283+
boost::buffers::string_buffer sb(&val);
284+
auto cb = sb.data();
285+
286+
finals += test_to_string(cb);
287287

288288
// Calculate how many bytes we expect to read on each iteration
289289
// std::size_t expected = chunking_expected_n(bs, cs, (i == 0),
290290
// total);
291291

292292
// Read into a buffer of size bs
293-
bws_.async_write_some(
294-
buf_.prepare(bs),
295-
chunking_handler(
296-
std::min(bs, cs), system::error_code{}, &total));
297-
298-
auto count = test::run(ioc_);
299-
if(i > 0) // The initial run reads the header so can call multiple
300-
// handlers.
293+
while(cb.size() > 0)
294+
{
295+
std::size_t emin, emax;
296+
if(srs_.capacity())
297+
{
298+
emin = std::max(
299+
(std::size_t)1, std::min({ bs, srs_.capacity() }));
300+
emax = emin;
301+
}
302+
else
303+
{
304+
emin = 1;
305+
emax = std::max((std::size_t)1, bs);
306+
}
307+
308+
std::size_t written = 0;
309+
bws_.async_write_some(
310+
cb,
311+
chunking_handler(
312+
system::error_code{},
313+
&written));
314+
315+
auto count = test::run(ioc_);
301316
BOOST_TEST_EQ(count, 1);
302317

303-
BOOST_TEST(sr_.is_done());
318+
BOOST_TEST_GE(written, emin);
319+
BOOST_TEST_LE(written, emax);
320+
321+
total += written;
322+
cb += written;
323+
324+
BOOST_TEST_GE(rts_.nwrite_bytes() - prev, 1);
325+
BOOST_TEST_LE(rts_.nwrite_bytes() - prev, cs);
326+
327+
prev = rts_.nwrite_bytes();
328+
329+
BOOST_TEST_LE(rts_.nwrite_bytes(), bs * (i+1) + header_length_);
330+
331+
BOOST_TEST(!sr_.is_done());
332+
}
304333
}
305334

335+
BOOST_TEST_EQ(total, bs * iters);
336+
337+
bws_.async_close(test::success_handler());
338+
339+
auto count = test::run(ioc_);
340+
BOOST_TEST_GE(count, 1);
341+
342+
BOOST_TEST_GT(rts_.nwrite_bytes(), iters + count - 1);
343+
BOOST_TEST_LE(rts_.nwrite_bytes(), cs * (iters + count));
344+
345+
BOOST_TEST_EQ(rts_.nwrite_bytes(), bs * iters + header_length_);
346+
306347
BOOST_TEST(sr_.is_done());
307-
BOOST_TEST_EQ(buf_.size(), body_length_);
308-
BOOST_TEST_EQ(total, body_length_);
309-
BOOST_TEST(test_to_string(buf_.data()) == body_);
348+
349+
BOOST_TEST(rts_.str() == header_ + finals);
310350
}
311351

312352
void
@@ -424,10 +464,11 @@ struct body_write_stream_test
424464
// sizes.
425465
{
426466
// Iterate through buffer sizes
427-
for(std::size_t bs = 1; bs < msg_length + 2; bs++)
467+
for(std::size_t bs = 1; bs < 1000; bs++)
428468
{
469+
std::cout << bs << std::endl;
429470
// Iterate through chunk sizes
430-
for(std::size_t cs = 1; cs < msg_length + 2; cs++)
471+
for(std::size_t cs = 1; cs < 1000; cs++)
431472
{
432473
single_tester().test_with_chunking(bs, cs);
433474
}

0 commit comments

Comments
 (0)