From 32100cbb8ddd908323510f7ffbb6a2c82841f68f Mon Sep 17 00:00:00 2001 From: "mbelshe@google.com" Date: Mon, 30 Nov 2009 18:24:46 +0000 Subject: Ressurrect the WriteError test by making a scoped method factory for the DelayedSocketDataProvider. The problem which crashed was that the lifecycle of the socket and the data provider are not coupled; and the posted message for a delayed ReadCompletion could be left hanging. BUG=none TEST=WriteError Review URL: http://codereview.chromium.org/452010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33300 0039d316-1c4b-4281-b951-d872f2087c98 --- net/flip/flip_network_transaction_unittest.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/net/flip/flip_network_transaction_unittest.cc b/net/flip/flip_network_transaction_unittest.cc index 767954c..e69382a 100644 --- a/net/flip/flip_network_transaction_unittest.cc +++ b/net/flip/flip_network_transaction_unittest.cc @@ -184,7 +184,8 @@ class DelayedSocketData : public StaticSocketDataProvider, // e.g. a MockRead(true, 0, 0); DelayedSocketData(MockRead* reads, int write_delay, MockWrite* writes) : StaticSocketDataProvider(reads, writes), - write_delay_(write_delay) { + write_delay_(write_delay), + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { DCHECK_GE(write_delay_, 0); } @@ -199,16 +200,24 @@ class DelayedSocketData : public StaticSocketDataProvider, // Now that our write has completed, we can allow reads to continue. if (!--write_delay_) MessageLoop::current()->PostDelayedTask(FROM_HERE, - NewRunnableMethod(this, &DelayedSocketData::CompleteRead), 100); + factory_.NewRunnableMethod(&DelayedSocketData::CompleteRead), 100); return rv; } + virtual void Reset() { + set_socket(NULL); + factory_.RevokeAll(); + StaticSocketDataProvider::Reset(); + } + void CompleteRead() { - socket()->OnReadComplete(GetNextRead()); + if (socket()) + socket()->OnReadComplete(GetNextRead()); } private: int write_delay_; + ScopedRunnableMethodFactory factory_; }; class FlipNetworkTransactionTest : public PlatformTest { @@ -738,10 +747,7 @@ TEST_F(FlipNetworkTransactionTest, DISABLED_ServerPush) { } // Test that we shutdown correctly on write errors. -// TODO(mbelshe): Fix this test. -// The problem is that the async IO can be left hanging in the mock -// socket, which can cause late-arriving events to crash. -TEST_F(FlipNetworkTransactionTest, DISABLED_WriteError) { +TEST_F(FlipNetworkTransactionTest, WriteError) { MockWrite writes[] = { // We'll write 10 bytes successfully MockWrite(true, reinterpret_cast(kGetSyn), 10), @@ -766,6 +772,7 @@ TEST_F(FlipNetworkTransactionTest, DISABLED_WriteError) { new DelayedSocketData(reads, 2, writes)); TransactionHelperResult out = TransactionHelper(request, data.get()); EXPECT_EQ(ERR_FAILED, out.rv); + data->Reset(); } // Test that partial writes work. -- cgit v1.1