diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 18:24:46 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 18:24:46 +0000 |
commit | 32100cbb8ddd908323510f7ffbb6a2c82841f68f (patch) | |
tree | ef0906fb8d3aedc076474f3164d63efdffce7c83 | |
parent | 6572f12401c12d3bae74df88cd4477fc063ffca3 (diff) | |
download | chromium_src-32100cbb8ddd908323510f7ffbb6a2c82841f68f.zip chromium_src-32100cbb8ddd908323510f7ffbb6a2c82841f68f.tar.gz chromium_src-32100cbb8ddd908323510f7ffbb6a2c82841f68f.tar.bz2 |
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
-rw-r--r-- | net/flip/flip_network_transaction_unittest.cc | 21 |
1 files 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<DelayedSocketData> 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<const char*>(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. |