1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/socket/socket_test_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "testing/platform_test.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 //-----------------------------------------------------------------------------
17 static const char kMsg1
[] = "\0hello!\xff";
18 static const int kLen1
= arraysize(kMsg1
);
19 static const char kMsg2
[] = "\0a2345678\0";
20 static const int kLen2
= arraysize(kMsg2
);
21 static const char kMsg3
[] = "bye!";
22 static const int kLen3
= arraysize(kMsg3
);
24 } // anonymous namespace
28 class DeterministicSocketDataTest
: public PlatformTest
{
30 DeterministicSocketDataTest();
32 void TearDown() override
;
34 void ReentrantReadCallback(int len
, int rv
);
35 void ReentrantWriteCallback(const char* data
, int len
, int rv
);
38 void Initialize(MockRead
* reads
, size_t reads_count
, MockWrite
* writes
,
41 void AssertSyncReadEquals(const char* data
, int len
);
42 void AssertAsyncReadEquals(const char* data
, int len
);
43 void AssertReadReturns(const char* data
, int len
, int rv
);
44 void AssertReadBufferEquals(const char* data
, int len
);
46 void AssertSyncWriteEquals(const char* data
, int len
);
47 void AssertAsyncWriteEquals(const char* data
, int len
);
48 void AssertWriteReturns(const char* data
, int len
, int rv
);
50 TestCompletionCallback read_callback_
;
51 TestCompletionCallback write_callback_
;
53 scoped_ptr
<DeterministicSocketData
> data_
;
56 scoped_refptr
<IOBuffer
> read_buf_
;
57 MockConnect connect_data_
;
59 HostPortPair endpoint_
;
60 scoped_refptr
<TransportSocketParams
> tcp_params_
;
61 DeterministicMockClientSocketFactory socket_factory_
;
62 MockTransportClientSocketPool socket_pool_
;
63 ClientSocketHandle connection_
;
65 DISALLOW_COPY_AND_ASSIGN(DeterministicSocketDataTest
);
68 DeterministicSocketDataTest::DeterministicSocketDataTest()
71 connect_data_(SYNCHRONOUS
, OK
),
72 endpoint_("www.google.com", 443),
73 tcp_params_(new TransportSocketParams(
77 OnHostResolutionCallback(),
78 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT
)),
79 socket_pool_(10, 10, &socket_factory_
) {
82 void DeterministicSocketDataTest::TearDown() {
83 // Empty the current queue.
84 base::MessageLoop::current()->RunUntilIdle();
85 PlatformTest::TearDown();
88 void DeterministicSocketDataTest::Initialize(MockRead
* reads
,
91 size_t writes_count
) {
92 data_
.reset(new DeterministicSocketData(reads
, reads_count
,
93 writes
, writes_count
));
94 data_
->set_connect_data(connect_data_
);
95 socket_factory_
.AddSocketDataProvider(data_
.get());
97 // Perform the TCP connect
99 connection_
.Init(endpoint_
.ToString(),
102 CompletionCallback(),
103 reinterpret_cast<TransportClientSocketPool
*>(&socket_pool_
),
105 sock_
= connection_
.socket();
108 void DeterministicSocketDataTest::AssertSyncReadEquals(const char* data
,
110 // Issue the read, which will complete immediately
111 AssertReadReturns(data
, len
, len
);
112 AssertReadBufferEquals(data
, len
);
115 void DeterministicSocketDataTest::AssertAsyncReadEquals(const char* data
,
117 // Issue the read, which will be completed asynchronously
118 AssertReadReturns(data
, len
, ERR_IO_PENDING
);
120 EXPECT_FALSE(read_callback_
.have_result());
121 EXPECT_TRUE(sock_
->IsConnected());
122 data_
->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked
124 // Now the read should complete
125 ASSERT_EQ(len
, read_callback_
.WaitForResult());
126 AssertReadBufferEquals(data
, len
);
129 void DeterministicSocketDataTest::AssertReadReturns(const char* data
,
131 read_buf_
= new IOBuffer(len
);
132 ASSERT_EQ(rv
, sock_
->Read(read_buf_
.get(), len
, read_callback_
.callback()));
135 void DeterministicSocketDataTest::AssertReadBufferEquals(const char* data
,
137 ASSERT_EQ(std::string(data
, len
), std::string(read_buf_
->data(), len
));
140 void DeterministicSocketDataTest::AssertSyncWriteEquals(const char* data
,
142 scoped_refptr
<IOBuffer
> buf(new IOBuffer(len
));
143 memcpy(buf
->data(), data
, len
);
145 // Issue the write, which will complete immediately
146 ASSERT_EQ(len
, sock_
->Write(buf
.get(), len
, write_callback_
.callback()));
149 void DeterministicSocketDataTest::AssertAsyncWriteEquals(const char* data
,
151 // Issue the read, which will be completed asynchronously
152 AssertWriteReturns(data
, len
, ERR_IO_PENDING
);
154 EXPECT_FALSE(read_callback_
.have_result());
155 EXPECT_TRUE(sock_
->IsConnected());
156 data_
->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked
158 ASSERT_EQ(len
, write_callback_
.WaitForResult());
161 void DeterministicSocketDataTest::AssertWriteReturns(const char* data
,
163 scoped_refptr
<IOBuffer
> buf(new IOBuffer(len
));
164 memcpy(buf
->data(), data
, len
);
166 // Issue the read, which will complete asynchronously
167 ASSERT_EQ(rv
, sock_
->Write(buf
.get(), len
, write_callback_
.callback()));
170 void DeterministicSocketDataTest::ReentrantReadCallback(int len
, int rv
) {
171 scoped_refptr
<IOBuffer
> read_buf(new IOBuffer(len
));
176 base::Bind(&DeterministicSocketDataTest::ReentrantReadCallback
,
177 base::Unretained(this),
181 void DeterministicSocketDataTest::ReentrantWriteCallback(
182 const char* data
, int len
, int rv
) {
183 scoped_refptr
<IOBuffer
> write_buf(new IOBuffer(len
));
184 memcpy(write_buf
->data(), data
, len
);
189 base::Bind(&DeterministicSocketDataTest::ReentrantWriteCallback
,
190 base::Unretained(this),
197 TEST_F(DeterministicSocketDataTest
, SingleSyncReadWhileStopped
) {
199 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
200 MockRead(SYNCHRONOUS
, 0, 1), // EOF
203 Initialize(reads
, arraysize(reads
), NULL
, 0);
205 data_
->SetStopped(true);
206 AssertReadReturns(kMsg1
, kLen1
, ERR_UNEXPECTED
);
209 TEST_F(DeterministicSocketDataTest
, SingleSyncReadTooEarly
) {
211 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 1), // Sync Read
212 MockRead(SYNCHRONOUS
, 0, 2), // EOF
215 MockWrite writes
[] = {
216 MockWrite(SYNCHRONOUS
, 0, 0)
219 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
222 ASSERT_FALSE(data_
->stopped());
223 AssertReadReturns(kMsg1
, kLen1
, ERR_UNEXPECTED
);
226 TEST_F(DeterministicSocketDataTest
, SingleSyncRead
) {
228 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
229 MockRead(SYNCHRONOUS
, 0, 1), // EOF
232 Initialize(reads
, arraysize(reads
), NULL
, 0);
233 // Make sure we don't stop before we've read all the data
235 AssertSyncReadEquals(kMsg1
, kLen1
);
238 TEST_F(DeterministicSocketDataTest
, MultipleSyncReads
) {
240 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
241 MockRead(SYNCHRONOUS
, kMsg2
, kLen2
, 1), // Sync Read
242 MockRead(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Read
243 MockRead(SYNCHRONOUS
, kMsg3
, kLen3
, 3), // Sync Read
244 MockRead(SYNCHRONOUS
, kMsg2
, kLen2
, 4), // Sync Read
245 MockRead(SYNCHRONOUS
, kMsg3
, kLen3
, 5), // Sync Read
246 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 6), // Sync Read
247 MockRead(SYNCHRONOUS
, 0, 7), // EOF
250 Initialize(reads
, arraysize(reads
), NULL
, 0);
252 // Make sure we don't stop before we've read all the data
253 data_
->StopAfter(10);
254 AssertSyncReadEquals(kMsg1
, kLen1
);
255 AssertSyncReadEquals(kMsg2
, kLen2
);
256 AssertSyncReadEquals(kMsg3
, kLen3
);
257 AssertSyncReadEquals(kMsg3
, kLen3
);
258 AssertSyncReadEquals(kMsg2
, kLen2
);
259 AssertSyncReadEquals(kMsg3
, kLen3
);
260 AssertSyncReadEquals(kMsg1
, kLen1
);
263 TEST_F(DeterministicSocketDataTest
, SingleAsyncRead
) {
265 MockRead(ASYNC
, kMsg1
, kLen1
, 0), // Async Read
266 MockRead(SYNCHRONOUS
, 0, 1), // EOF
269 Initialize(reads
, arraysize(reads
), NULL
, 0);
271 AssertAsyncReadEquals(kMsg1
, kLen1
);
274 TEST_F(DeterministicSocketDataTest
, MultipleAsyncReads
) {
276 MockRead(ASYNC
, kMsg1
, kLen1
, 0), // Async Read
277 MockRead(ASYNC
, kMsg2
, kLen2
, 1), // Async Read
278 MockRead(ASYNC
, kMsg3
, kLen3
, 2), // Async Read
279 MockRead(ASYNC
, kMsg3
, kLen3
, 3), // Async Read
280 MockRead(ASYNC
, kMsg2
, kLen2
, 4), // Async Read
281 MockRead(ASYNC
, kMsg3
, kLen3
, 5), // Async Read
282 MockRead(ASYNC
, kMsg1
, kLen1
, 6), // Async Read
283 MockRead(SYNCHRONOUS
, 0, 7), // EOF
286 Initialize(reads
, arraysize(reads
), NULL
, 0);
288 AssertAsyncReadEquals(kMsg1
, kLen1
);
289 AssertAsyncReadEquals(kMsg2
, kLen2
);
290 AssertAsyncReadEquals(kMsg3
, kLen3
);
291 AssertAsyncReadEquals(kMsg3
, kLen3
);
292 AssertAsyncReadEquals(kMsg2
, kLen2
);
293 AssertAsyncReadEquals(kMsg3
, kLen3
);
294 AssertAsyncReadEquals(kMsg1
, kLen1
);
297 TEST_F(DeterministicSocketDataTest
, MixedReads
) {
299 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
300 MockRead(ASYNC
, kMsg2
, kLen2
, 1), // Async Read
301 MockRead(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Read
302 MockRead(ASYNC
, kMsg3
, kLen3
, 3), // Async Read
303 MockRead(SYNCHRONOUS
, kMsg2
, kLen2
, 4), // Sync Read
304 MockRead(ASYNC
, kMsg3
, kLen3
, 5), // Async Read
305 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 6), // Sync Read
306 MockRead(SYNCHRONOUS
, 0, 7), // EOF
309 Initialize(reads
, arraysize(reads
), NULL
, 0);
312 AssertSyncReadEquals(kMsg1
, kLen1
);
313 AssertAsyncReadEquals(kMsg2
, kLen2
);
315 AssertSyncReadEquals(kMsg3
, kLen3
);
316 AssertAsyncReadEquals(kMsg3
, kLen3
);
318 AssertSyncReadEquals(kMsg2
, kLen2
);
319 AssertAsyncReadEquals(kMsg3
, kLen3
);
321 AssertSyncReadEquals(kMsg1
, kLen1
);
324 TEST_F(DeterministicSocketDataTest
, SyncReadFromCompletionCallback
) {
326 MockRead(ASYNC
, kMsg1
, kLen1
, 0), // Async Read
327 MockRead(SYNCHRONOUS
, kMsg2
, kLen2
, 1), // Sync Read
330 Initialize(reads
, arraysize(reads
), NULL
, 0);
334 scoped_refptr
<IOBuffer
> read_buf(new IOBuffer(kLen1
));
335 ASSERT_EQ(ERR_IO_PENDING
,
339 base::Bind(&DeterministicSocketDataTest::ReentrantReadCallback
,
340 base::Unretained(this),
347 TEST_F(DeterministicSocketDataTest
, SingleSyncWriteWhileStopped
) {
348 MockWrite writes
[] = {
349 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
352 Initialize(NULL
, 0, writes
, arraysize(writes
));
354 data_
->SetStopped(true);
355 AssertWriteReturns(kMsg1
, kLen1
, ERR_UNEXPECTED
);
358 TEST_F(DeterministicSocketDataTest
, SingleSyncWriteTooEarly
) {
359 MockWrite writes
[] = {
360 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 1), // Sync Write
364 MockRead(SYNCHRONOUS
, 0, 0)
367 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
370 ASSERT_FALSE(data_
->stopped());
371 AssertWriteReturns(kMsg1
, kLen1
, ERR_UNEXPECTED
);
374 TEST_F(DeterministicSocketDataTest
, SingleSyncWrite
) {
375 MockWrite writes
[] = {
376 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Write
379 Initialize(NULL
, 0, writes
, arraysize(writes
));
381 // Make sure we don't stop before we've read all the data
383 AssertSyncWriteEquals(kMsg1
, kLen1
);
386 TEST_F(DeterministicSocketDataTest
, MultipleSyncWrites
) {
387 MockWrite writes
[] = {
388 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Write
389 MockWrite(SYNCHRONOUS
, kMsg2
, kLen2
, 1), // Sync Write
390 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Write
391 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 3), // Sync Write
392 MockWrite(SYNCHRONOUS
, kMsg2
, kLen2
, 4), // Sync Write
393 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 5), // Sync Write
394 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 6), // Sync Write
397 Initialize(NULL
, 0, writes
, arraysize(writes
));
399 // Make sure we don't stop before we've read all the data
400 data_
->StopAfter(10);
401 AssertSyncWriteEquals(kMsg1
, kLen1
);
402 AssertSyncWriteEquals(kMsg2
, kLen2
);
403 AssertSyncWriteEquals(kMsg3
, kLen3
);
404 AssertSyncWriteEquals(kMsg3
, kLen3
);
405 AssertSyncWriteEquals(kMsg2
, kLen2
);
406 AssertSyncWriteEquals(kMsg3
, kLen3
);
407 AssertSyncWriteEquals(kMsg1
, kLen1
);
410 TEST_F(DeterministicSocketDataTest
, SingleAsyncWrite
) {
411 MockWrite writes
[] = {
412 MockWrite(ASYNC
, kMsg1
, kLen1
, 0), // Async Write
415 Initialize(NULL
, 0, writes
, arraysize(writes
));
417 AssertAsyncWriteEquals(kMsg1
, kLen1
);
420 TEST_F(DeterministicSocketDataTest
, MultipleAsyncWrites
) {
421 MockWrite writes
[] = {
422 MockWrite(ASYNC
, kMsg1
, kLen1
, 0), // Async Write
423 MockWrite(ASYNC
, kMsg2
, kLen2
, 1), // Async Write
424 MockWrite(ASYNC
, kMsg3
, kLen3
, 2), // Async Write
425 MockWrite(ASYNC
, kMsg3
, kLen3
, 3), // Async Write
426 MockWrite(ASYNC
, kMsg2
, kLen2
, 4), // Async Write
427 MockWrite(ASYNC
, kMsg3
, kLen3
, 5), // Async Write
428 MockWrite(ASYNC
, kMsg1
, kLen1
, 6), // Async Write
431 Initialize(NULL
, 0, writes
, arraysize(writes
));
433 AssertAsyncWriteEquals(kMsg1
, kLen1
);
434 AssertAsyncWriteEquals(kMsg2
, kLen2
);
435 AssertAsyncWriteEquals(kMsg3
, kLen3
);
436 AssertAsyncWriteEquals(kMsg3
, kLen3
);
437 AssertAsyncWriteEquals(kMsg2
, kLen2
);
438 AssertAsyncWriteEquals(kMsg3
, kLen3
);
439 AssertAsyncWriteEquals(kMsg1
, kLen1
);
442 TEST_F(DeterministicSocketDataTest
, MixedWrites
) {
443 MockWrite writes
[] = {
444 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Write
445 MockWrite(ASYNC
, kMsg2
, kLen2
, 1), // Async Write
446 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Write
447 MockWrite(ASYNC
, kMsg3
, kLen3
, 3), // Async Write
448 MockWrite(SYNCHRONOUS
, kMsg2
, kLen2
, 4), // Sync Write
449 MockWrite(ASYNC
, kMsg3
, kLen3
, 5), // Async Write
450 MockWrite(SYNCHRONOUS
, kMsg1
, kLen1
, 6), // Sync Write
453 Initialize(NULL
, 0, writes
, arraysize(writes
));
456 AssertSyncWriteEquals(kMsg1
, kLen1
);
457 AssertAsyncWriteEquals(kMsg2
, kLen2
);
459 AssertSyncWriteEquals(kMsg3
, kLen3
);
460 AssertAsyncWriteEquals(kMsg3
, kLen3
);
462 AssertSyncWriteEquals(kMsg2
, kLen2
);
463 AssertAsyncWriteEquals(kMsg3
, kLen3
);
465 AssertSyncWriteEquals(kMsg1
, kLen1
);
468 TEST_F(DeterministicSocketDataTest
, SyncWriteFromCompletionCallback
) {
469 MockWrite writes
[] = {
470 MockWrite(ASYNC
, kMsg1
, kLen1
, 0), // Async Write
471 MockWrite(SYNCHRONOUS
, kMsg2
, kLen2
, 1), // Sync Write
474 Initialize(NULL
, 0, writes
, arraysize(writes
));
478 scoped_refptr
<IOBuffer
> write_buf(new IOBuffer(kLen1
));
479 memcpy(write_buf
->data(), kMsg1
, kLen1
);
480 ASSERT_EQ(ERR_IO_PENDING
,
484 base::Bind(&DeterministicSocketDataTest::ReentrantWriteCallback
,
485 base::Unretained(this),
491 // ----------- Mixed Reads and Writes
493 TEST_F(DeterministicSocketDataTest
, MixedSyncOperations
) {
495 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
496 MockRead(SYNCHRONOUS
, kMsg2
, kLen2
, 3), // Sync Read
497 MockRead(SYNCHRONOUS
, 0, 4), // EOF
500 MockWrite writes
[] = {
501 MockWrite(SYNCHRONOUS
, kMsg2
, kLen2
, 1), // Sync Write
502 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Write
505 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
507 // Make sure we don't stop before we've read/written everything
508 data_
->StopAfter(10);
509 AssertSyncReadEquals(kMsg1
, kLen1
);
510 AssertSyncWriteEquals(kMsg2
, kLen2
);
511 AssertSyncWriteEquals(kMsg3
, kLen3
);
512 AssertSyncReadEquals(kMsg2
, kLen2
);
515 TEST_F(DeterministicSocketDataTest
, MixedAsyncOperations
) {
517 MockRead(ASYNC
, kMsg1
, kLen1
, 0), // Sync Read
518 MockRead(ASYNC
, kMsg2
, kLen2
, 3), // Sync Read
519 MockRead(ASYNC
, 0, 4), // EOF
522 MockWrite writes
[] = {
523 MockWrite(ASYNC
, kMsg2
, kLen2
, 1), // Sync Write
524 MockWrite(ASYNC
, kMsg3
, kLen3
, 2), // Sync Write
527 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
529 AssertAsyncReadEquals(kMsg1
, kLen1
);
530 AssertAsyncWriteEquals(kMsg2
, kLen2
);
531 AssertAsyncWriteEquals(kMsg3
, kLen3
);
532 AssertAsyncReadEquals(kMsg2
, kLen2
);
535 TEST_F(DeterministicSocketDataTest
, InterleavedAsyncOperations
) {
536 // Order of completion is read, write, write, read
538 MockRead(ASYNC
, kMsg1
, kLen1
, 0), // Async Read
539 MockRead(ASYNC
, kMsg2
, kLen2
, 3), // Async Read
540 MockRead(ASYNC
, 0, 4), // EOF
543 MockWrite writes
[] = {
544 MockWrite(ASYNC
, kMsg2
, kLen2
, 1), // Async Write
545 MockWrite(ASYNC
, kMsg3
, kLen3
, 2), // Async Write
548 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
550 // Issue the write, which will block until the read completes
551 AssertWriteReturns(kMsg2
, kLen2
, ERR_IO_PENDING
);
553 // Issue the read which will return first
554 AssertReadReturns(kMsg1
, kLen1
, ERR_IO_PENDING
);
557 ASSERT_TRUE(read_callback_
.have_result());
558 ASSERT_EQ(kLen1
, read_callback_
.WaitForResult());
559 AssertReadBufferEquals(kMsg1
, kLen1
);
562 ASSERT_TRUE(write_callback_
.have_result());
563 ASSERT_EQ(kLen2
, write_callback_
.WaitForResult());
566 // Issue the read, which will block until the write completes
567 AssertReadReturns(kMsg2
, kLen2
, ERR_IO_PENDING
);
569 // Issue the writes which will return first
570 AssertWriteReturns(kMsg3
, kLen3
, ERR_IO_PENDING
);
573 ASSERT_TRUE(write_callback_
.have_result());
574 ASSERT_EQ(kLen3
, write_callback_
.WaitForResult());
577 ASSERT_TRUE(read_callback_
.have_result());
578 ASSERT_EQ(kLen2
, read_callback_
.WaitForResult());
579 AssertReadBufferEquals(kMsg2
, kLen2
);
582 TEST_F(DeterministicSocketDataTest
, InterleavedMixedOperations
) {
583 // Order of completion is read, write, write, read
585 MockRead(SYNCHRONOUS
, kMsg1
, kLen1
, 0), // Sync Read
586 MockRead(ASYNC
, kMsg2
, kLen2
, 3), // Async Read
587 MockRead(SYNCHRONOUS
, 0, 4), // EOF
590 MockWrite writes
[] = {
591 MockWrite(ASYNC
, kMsg2
, kLen2
, 1), // Async Write
592 MockWrite(SYNCHRONOUS
, kMsg3
, kLen3
, 2), // Sync Write
595 Initialize(reads
, arraysize(reads
), writes
, arraysize(writes
));
597 // Issue the write, which will block until the read completes
598 AssertWriteReturns(kMsg2
, kLen2
, ERR_IO_PENDING
);
600 // Issue the writes which will complete immediately
602 AssertSyncReadEquals(kMsg1
, kLen1
);
605 ASSERT_TRUE(write_callback_
.have_result());
606 ASSERT_EQ(kLen2
, write_callback_
.WaitForResult());
608 // Issue the read, which will block until the write completes
609 AssertReadReturns(kMsg2
, kLen2
, ERR_IO_PENDING
);
611 // Issue the writes which will complete immediately
613 AssertSyncWriteEquals(kMsg3
, kLen3
);
616 ASSERT_TRUE(read_callback_
.have_result());
617 ASSERT_EQ(kLen2
, read_callback_
.WaitForResult());
618 AssertReadBufferEquals(kMsg2
, kLen2
);