Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: net/socket/sequenced_socket_data_unittest.cc

Issue 2053133002: Remove MessageLoop::current()->RunUntilIdle() in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_stream_factory_test.cc ('k') | net/socket/socks_client_socket_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 Initialize(reads, arraysize(reads), nullptr, 0); 483 Initialize(reads, arraysize(reads), nullptr, 0);
484 484
485 read_buf_ = new IOBuffer(kLen1); 485 read_buf_ = new IOBuffer(kLen1);
486 ASSERT_EQ( 486 ASSERT_EQ(
487 ERR_IO_PENDING, 487 ERR_IO_PENDING,
488 sock_->Read( 488 sock_->Read(
489 read_buf_.get(), kLen1, 489 read_buf_.get(), kLen1,
490 base::Bind(&SequencedSocketDataTest::ReentrantReadCallback, 490 base::Bind(&SequencedSocketDataTest::ReentrantReadCallback,
491 base::Unretained(this), kMsg1, kLen1, kLen2, kLen2))); 491 base::Unretained(this), kMsg1, kLen1, kLen2, kLen2)));
492 492
493 base::MessageLoop::current()->RunUntilIdle(); 493 base::RunLoop().RunUntilIdle();
494 AssertReadBufferEquals(kMsg2, kLen2); 494 AssertReadBufferEquals(kMsg2, kLen2);
495 } 495 }
496 496
497 TEST_F(SequencedSocketDataTest, ManyReentrantReads) { 497 TEST_F(SequencedSocketDataTest, ManyReentrantReads) {
498 MockRead reads[] = { 498 MockRead reads[] = {
499 MockRead(ASYNC, kMsg1, kLen1, 0), 499 MockRead(ASYNC, kMsg1, kLen1, 0),
500 MockRead(ASYNC, kMsg2, kLen2, 1), 500 MockRead(ASYNC, kMsg2, kLen2, 1),
501 MockRead(ASYNC, kMsg3, kLen3, 2), 501 MockRead(ASYNC, kMsg3, kLen3, 2),
502 MockRead(ASYNC, kMsg4, kLen4, 3), 502 MockRead(ASYNC, kMsg4, kLen4, 3),
503 }; 503 };
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 608
609 Initialize(reads, arraysize(reads), nullptr, 0); 609 Initialize(reads, arraysize(reads), nullptr, 0);
610 610
611 scoped_refptr<IOBuffer> read_buf(new IOBuffer(1)); 611 scoped_refptr<IOBuffer> read_buf(new IOBuffer(1));
612 ASSERT_EQ(ERR_IO_PENDING, 612 ASSERT_EQ(ERR_IO_PENDING,
613 sock_->Read(read_buf.get(), 1, read_callback_.callback())); 613 sock_->Read(read_buf.get(), 1, read_callback_.callback()));
614 ASSERT_FALSE(read_callback_.have_result()); 614 ASSERT_FALSE(read_callback_.have_result());
615 615
616 // Even though the read is scheduled to complete at sequence number 0, 616 // Even though the read is scheduled to complete at sequence number 0,
617 // verify that the read callback in never called. 617 // verify that the read callback in never called.
618 base::MessageLoop::current()->RunUntilIdle(); 618 base::RunLoop().RunUntilIdle();
619 ASSERT_FALSE(read_callback_.have_result()); 619 ASSERT_FALSE(read_callback_.have_result());
620 } 620 }
621 621
622 // ----------- Write 622 // ----------- Write
623 623
624 TEST_F(SequencedSocketDataTest, SingleSyncWriteTooEarly) { 624 TEST_F(SequencedSocketDataTest, SingleSyncWriteTooEarly) {
625 MockWrite writes[] = { 625 MockWrite writes[] = {
626 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 1), 626 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 1),
627 }; 627 };
628 628
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 788
789 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1)); 789 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1));
790 memcpy(write_buf->data(), kMsg1, kLen1); 790 memcpy(write_buf->data(), kMsg1, kLen1);
791 ASSERT_EQ( 791 ASSERT_EQ(
792 ERR_IO_PENDING, 792 ERR_IO_PENDING,
793 sock_->Write( 793 sock_->Write(
794 write_buf.get(), kLen1, 794 write_buf.get(), kLen1,
795 base::Bind(&SequencedSocketDataTest::ReentrantWriteCallback, 795 base::Bind(&SequencedSocketDataTest::ReentrantWriteCallback,
796 base::Unretained(this), kLen1, kMsg2, kLen2, kLen2))); 796 base::Unretained(this), kLen1, kMsg2, kLen2, kLen2)));
797 797
798 base::MessageLoop::current()->RunUntilIdle(); 798 base::RunLoop().RunUntilIdle();
799 } 799 }
800 800
801 TEST_F(SequencedSocketDataTest, AsyncWriteFromCompletionCallback) { 801 TEST_F(SequencedSocketDataTest, AsyncWriteFromCompletionCallback) {
802 MockWrite writes[] = { 802 MockWrite writes[] = {
803 MockWrite(ASYNC, kMsg1, kLen1, 0), MockWrite(ASYNC, kMsg2, kLen2, 1), 803 MockWrite(ASYNC, kMsg1, kLen1, 0), MockWrite(ASYNC, kMsg2, kLen2, 1),
804 }; 804 };
805 805
806 Initialize(nullptr, 0, writes, arraysize(writes)); 806 Initialize(nullptr, 0, writes, arraysize(writes));
807 807
808 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1)); 808 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1));
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 ReentrantHelper helper(sock_); 1073 ReentrantHelper helper(sock_);
1074 helper.SetExpectedWrite(kLen1); 1074 helper.SetExpectedWrite(kLen1);
1075 helper.SetInvokeRead(helper2.read_buf(), kLen2, ERR_IO_PENDING, 1075 helper.SetInvokeRead(helper2.read_buf(), kLen2, ERR_IO_PENDING,
1076 helper2.callback()); 1076 helper2.callback());
1077 1077
1078 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1)); 1078 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1));
1079 memcpy(write_buf->data(), kMsg1, kLen1); 1079 memcpy(write_buf->data(), kMsg1, kLen1);
1080 ASSERT_EQ(ERR_IO_PENDING, 1080 ASSERT_EQ(ERR_IO_PENDING,
1081 sock_->Write(write_buf.get(), kLen1, helper.callback())); 1081 sock_->Write(write_buf.get(), kLen1, helper.callback()));
1082 1082
1083 base::MessageLoop::current()->RunUntilIdle(); 1083 base::RunLoop().RunUntilIdle();
1084 AssertReadBufferEquals(kMsg4, kLen4); 1084 AssertReadBufferEquals(kMsg4, kLen4);
1085 } 1085 }
1086 1086
1087 TEST_F(SequencedSocketDataTest, MixedReentrantOperationsThenSynchronousWrite) { 1087 TEST_F(SequencedSocketDataTest, MixedReentrantOperationsThenSynchronousWrite) {
1088 MockWrite writes[] = { 1088 MockWrite writes[] = {
1089 MockWrite(ASYNC, kMsg2, kLen2, 1), 1089 MockWrite(ASYNC, kMsg2, kLen2, 1),
1090 MockWrite(SYNCHRONOUS, kMsg4, kLen4, 3), 1090 MockWrite(SYNCHRONOUS, kMsg4, kLen4, 3),
1091 }; 1091 };
1092 1092
1093 MockRead reads[] = { 1093 MockRead reads[] = {
(...skipping 13 matching lines...) Expand all
1107 helper2.SetInvokeRead(helper3.read_buf(), kLen3, ERR_IO_PENDING, 1107 helper2.SetInvokeRead(helper3.read_buf(), kLen3, ERR_IO_PENDING,
1108 helper3.callback()); 1108 helper3.callback());
1109 1109
1110 ReentrantHelper helper(sock_); 1110 ReentrantHelper helper(sock_);
1111 helper.SetExpectedRead(kMsg1, kLen1); 1111 helper.SetExpectedRead(kMsg1, kLen1);
1112 helper.SetInvokeWrite(kMsg2, kLen2, ERR_IO_PENDING, helper2.callback()); 1112 helper.SetInvokeWrite(kMsg2, kLen2, ERR_IO_PENDING, helper2.callback());
1113 1113
1114 ASSERT_EQ(ERR_IO_PENDING, 1114 ASSERT_EQ(ERR_IO_PENDING,
1115 sock_->Read(helper.read_buf().get(), kLen1, helper.callback())); 1115 sock_->Read(helper.read_buf().get(), kLen1, helper.callback()));
1116 1116
1117 base::MessageLoop::current()->RunUntilIdle(); 1117 base::RunLoop().RunUntilIdle();
1118 } 1118 }
1119 1119
1120 // Test the basic case where a read is paused. 1120 // Test the basic case where a read is paused.
1121 TEST_F(SequencedSocketDataTest, PauseAndResume_PauseRead) { 1121 TEST_F(SequencedSocketDataTest, PauseAndResume_PauseRead) {
1122 MockRead reads[] = { 1122 MockRead reads[] = {
1123 MockRead(ASYNC, ERR_IO_PENDING, 0), MockRead(ASYNC, kMsg1, kLen1, 1), 1123 MockRead(ASYNC, ERR_IO_PENDING, 0), MockRead(ASYNC, kMsg1, kLen1, 1),
1124 }; 1124 };
1125 1125
1126 Initialize(reads, arraysize(reads), nullptr, 0); 1126 Initialize(reads, arraysize(reads), nullptr, 0);
1127 1127
1128 AssertReadReturns(kLen1, ERR_IO_PENDING); 1128 AssertReadReturns(kLen1, ERR_IO_PENDING);
1129 ASSERT_FALSE(read_callback_.have_result()); 1129 ASSERT_FALSE(read_callback_.have_result());
1130 1130
1131 RunUntilPaused(); 1131 RunUntilPaused();
1132 ASSERT_TRUE(IsPaused()); 1132 ASSERT_TRUE(IsPaused());
1133 1133
1134 // Spinning the message loop should do nothing. 1134 // Spinning the message loop should do nothing.
1135 base::MessageLoop::current()->RunUntilIdle(); 1135 base::RunLoop().RunUntilIdle();
1136 ASSERT_FALSE(read_callback_.have_result()); 1136 ASSERT_FALSE(read_callback_.have_result());
1137 ASSERT_TRUE(IsPaused()); 1137 ASSERT_TRUE(IsPaused());
1138 1138
1139 Resume(); 1139 Resume();
1140 ASSERT_FALSE(IsPaused()); 1140 ASSERT_FALSE(IsPaused());
1141 ASSERT_TRUE(read_callback_.have_result()); 1141 ASSERT_TRUE(read_callback_.have_result());
1142 ASSERT_EQ(kLen1, read_callback_.WaitForResult()); 1142 ASSERT_EQ(kLen1, read_callback_.WaitForResult());
1143 AssertReadBufferEquals(kMsg1, kLen1); 1143 AssertReadBufferEquals(kMsg1, kLen1);
1144 } 1144 }
1145 1145
1146 // Test the case where a read that will be paused is started before write that 1146 // Test the case where a read that will be paused is started before write that
1147 // completes before the pause. 1147 // completes before the pause.
1148 TEST_F(SequencedSocketDataTest, PauseAndResume_WritePauseRead) { 1148 TEST_F(SequencedSocketDataTest, PauseAndResume_WritePauseRead) {
1149 MockWrite writes[] = { 1149 MockWrite writes[] = {
1150 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), 1150 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0),
1151 }; 1151 };
1152 1152
1153 MockRead reads[] = { 1153 MockRead reads[] = {
1154 MockRead(ASYNC, ERR_IO_PENDING, 1), MockRead(ASYNC, kMsg2, kLen2, 2), 1154 MockRead(ASYNC, ERR_IO_PENDING, 1), MockRead(ASYNC, kMsg2, kLen2, 2),
1155 }; 1155 };
1156 1156
1157 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1157 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1158 1158
1159 AssertReadReturns(kLen2, ERR_IO_PENDING); 1159 AssertReadReturns(kLen2, ERR_IO_PENDING);
1160 ASSERT_FALSE(read_callback_.have_result()); 1160 ASSERT_FALSE(read_callback_.have_result());
1161 1161
1162 // Nothing should happen until the write starts. 1162 // Nothing should happen until the write starts.
1163 base::MessageLoop::current()->RunUntilIdle(); 1163 base::RunLoop().RunUntilIdle();
1164 ASSERT_FALSE(read_callback_.have_result()); 1164 ASSERT_FALSE(read_callback_.have_result());
1165 ASSERT_FALSE(IsPaused()); 1165 ASSERT_FALSE(IsPaused());
1166 1166
1167 AssertSyncWriteEquals(kMsg1, kLen1); 1167 AssertSyncWriteEquals(kMsg1, kLen1);
1168 1168
1169 RunUntilPaused(); 1169 RunUntilPaused();
1170 ASSERT_FALSE(read_callback_.have_result()); 1170 ASSERT_FALSE(read_callback_.have_result());
1171 ASSERT_TRUE(IsPaused()); 1171 ASSERT_TRUE(IsPaused());
1172 1172
1173 // Spinning the message loop should do nothing. 1173 // Spinning the message loop should do nothing.
1174 base::MessageLoop::current()->RunUntilIdle(); 1174 base::RunLoop().RunUntilIdle();
1175 ASSERT_FALSE(read_callback_.have_result()); 1175 ASSERT_FALSE(read_callback_.have_result());
1176 ASSERT_TRUE(IsPaused()); 1176 ASSERT_TRUE(IsPaused());
1177 1177
1178 Resume(); 1178 Resume();
1179 ASSERT_FALSE(IsPaused()); 1179 ASSERT_FALSE(IsPaused());
1180 ASSERT_TRUE(read_callback_.have_result()); 1180 ASSERT_TRUE(read_callback_.have_result());
1181 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); 1181 ASSERT_EQ(kLen2, read_callback_.WaitForResult());
1182 AssertReadBufferEquals(kMsg2, kLen2); 1182 AssertReadBufferEquals(kMsg2, kLen2);
1183 } 1183 }
1184 1184
1185 // Test the basic case where a write is paused. 1185 // Test the basic case where a write is paused.
1186 TEST_F(SequencedSocketDataTest, PauseAndResume_PauseWrite) { 1186 TEST_F(SequencedSocketDataTest, PauseAndResume_PauseWrite) {
1187 MockWrite writes[] = { 1187 MockWrite writes[] = {
1188 MockWrite(ASYNC, ERR_IO_PENDING, 0), MockWrite(ASYNC, kMsg1, kLen1, 1), 1188 MockWrite(ASYNC, ERR_IO_PENDING, 0), MockWrite(ASYNC, kMsg1, kLen1, 1),
1189 }; 1189 };
1190 1190
1191 Initialize(nullptr, 0, writes, arraysize(writes)); 1191 Initialize(nullptr, 0, writes, arraysize(writes));
1192 1192
1193 AssertWriteReturns(kMsg1, kLen1, ERR_IO_PENDING); 1193 AssertWriteReturns(kMsg1, kLen1, ERR_IO_PENDING);
1194 ASSERT_FALSE(write_callback_.have_result()); 1194 ASSERT_FALSE(write_callback_.have_result());
1195 1195
1196 RunUntilPaused(); 1196 RunUntilPaused();
1197 ASSERT_TRUE(IsPaused()); 1197 ASSERT_TRUE(IsPaused());
1198 1198
1199 // Spinning the message loop should do nothing. 1199 // Spinning the message loop should do nothing.
1200 base::MessageLoop::current()->RunUntilIdle(); 1200 base::RunLoop().RunUntilIdle();
1201 ASSERT_FALSE(write_callback_.have_result()); 1201 ASSERT_FALSE(write_callback_.have_result());
1202 ASSERT_TRUE(IsPaused()); 1202 ASSERT_TRUE(IsPaused());
1203 1203
1204 Resume(); 1204 Resume();
1205 ASSERT_FALSE(IsPaused()); 1205 ASSERT_FALSE(IsPaused());
1206 ASSERT_TRUE(write_callback_.have_result()); 1206 ASSERT_TRUE(write_callback_.have_result());
1207 ASSERT_EQ(kLen1, write_callback_.WaitForResult()); 1207 ASSERT_EQ(kLen1, write_callback_.WaitForResult());
1208 } 1208 }
1209 1209
1210 // Test the case where a write that will be paused is started before read that 1210 // Test the case where a write that will be paused is started before read that
1211 // completes before the pause. 1211 // completes before the pause.
1212 TEST_F(SequencedSocketDataTest, PauseAndResume_ReadPauseWrite) { 1212 TEST_F(SequencedSocketDataTest, PauseAndResume_ReadPauseWrite) {
1213 MockWrite writes[] = { 1213 MockWrite writes[] = {
1214 MockWrite(ASYNC, ERR_IO_PENDING, 1), MockWrite(ASYNC, kMsg2, kLen2, 2), 1214 MockWrite(ASYNC, ERR_IO_PENDING, 1), MockWrite(ASYNC, kMsg2, kLen2, 2),
1215 }; 1215 };
1216 1216
1217 MockRead reads[] = { 1217 MockRead reads[] = {
1218 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), 1218 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0),
1219 }; 1219 };
1220 1220
1221 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1221 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1222 1222
1223 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING); 1223 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING);
1224 ASSERT_FALSE(write_callback_.have_result()); 1224 ASSERT_FALSE(write_callback_.have_result());
1225 1225
1226 // Nothing should happen until the write starts. 1226 // Nothing should happen until the write starts.
1227 base::MessageLoop::current()->RunUntilIdle(); 1227 base::RunLoop().RunUntilIdle();
1228 ASSERT_FALSE(write_callback_.have_result()); 1228 ASSERT_FALSE(write_callback_.have_result());
1229 ASSERT_FALSE(IsPaused()); 1229 ASSERT_FALSE(IsPaused());
1230 1230
1231 AssertSyncReadEquals(kMsg1, kLen1); 1231 AssertSyncReadEquals(kMsg1, kLen1);
1232 1232
1233 RunUntilPaused(); 1233 RunUntilPaused();
1234 ASSERT_FALSE(write_callback_.have_result()); 1234 ASSERT_FALSE(write_callback_.have_result());
1235 ASSERT_TRUE(IsPaused()); 1235 ASSERT_TRUE(IsPaused());
1236 1236
1237 // Spinning the message loop should do nothing. 1237 // Spinning the message loop should do nothing.
1238 base::MessageLoop::current()->RunUntilIdle(); 1238 base::RunLoop().RunUntilIdle();
1239 ASSERT_FALSE(write_callback_.have_result()); 1239 ASSERT_FALSE(write_callback_.have_result());
1240 ASSERT_TRUE(IsPaused()); 1240 ASSERT_TRUE(IsPaused());
1241 1241
1242 Resume(); 1242 Resume();
1243 ASSERT_FALSE(IsPaused()); 1243 ASSERT_FALSE(IsPaused());
1244 ASSERT_TRUE(write_callback_.have_result()); 1244 ASSERT_TRUE(write_callback_.have_result());
1245 ASSERT_EQ(kLen2, write_callback_.WaitForResult()); 1245 ASSERT_EQ(kLen2, write_callback_.WaitForResult());
1246 } 1246 }
1247 1247
1248 } // namespace 1248 } // namespace
1249 1249
1250 } // namespace net 1250 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory_test.cc ('k') | net/socket/socks_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698