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

Unified Diff: net/socket/ssl_server_socket_unittest.cc

Issue 7399025: Fix instability in SSL client/server sockets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/ssl_server_socket_nss.cc ('k') | remoting/protocol/jingle_session_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/ssl_server_socket_unittest.cc
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index 1ab9f63923f85f8a9870527b20cb53d89c66b12f..2d675c910e762a536872a0ced4e53d5bb7fd81bc 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -15,10 +15,14 @@
#include "net/socket/ssl_server_socket.h"
+#include <stdlib.h>
+
#include <queue>
+#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "crypto/nss_util.h"
#include "crypto/rsa_private_key.h"
@@ -46,7 +50,10 @@ namespace {
class FakeDataChannel {
public:
- FakeDataChannel() : read_callback_(NULL), read_buf_len_(0) {
+ FakeDataChannel()
+ : read_callback_(NULL),
+ read_buf_len_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
}
virtual int Read(IOBuffer* buf, int buf_len,
@@ -63,13 +70,15 @@ class FakeDataChannel {
virtual int Write(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
data_.push(new net::DrainableIOBuffer(buf, buf_len));
- DoReadCallback();
+ MessageLoop::current()->PostTask(
+ FROM_HERE, task_factory_.NewRunnableMethod(
+ &FakeDataChannel::DoReadCallback));
return buf_len;
}
private:
void DoReadCallback() {
- if (!read_callback_)
+ if (!read_callback_ || data_.empty())
return;
int copied = PropogateData(read_buf_, read_buf_len_);
@@ -97,6 +106,8 @@ class FakeDataChannel {
std::queue<scoped_refptr<net::DrainableIOBuffer> > data_;
+ ScopedRunnableMethodFactory<FakeDataChannel> task_factory_;
+
DISALLOW_COPY_AND_ASSIGN(FakeDataChannel);
};
@@ -109,16 +120,19 @@ class FakeSocket : public StreamSocket {
}
virtual ~FakeSocket() {
-
}
virtual int Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
+ // Read random number of bytes.
+ buf_len = rand() % buf_len + 1;
return incoming_->Read(buf, buf_len, callback);
}
virtual int Write(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
+ // Write random number of bytes.
+ buf_len = rand() % buf_len + 1;
return outgoing_->Write(buf, buf_len, callback);
}
@@ -204,17 +218,28 @@ TEST(FakeSocketTest, DataTransfer) {
scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(kReadBufSize);
// Write then read.
- EXPECT_EQ(kTestDataSize, server.Write(write_buf, kTestDataSize, NULL));
- EXPECT_EQ(kTestDataSize, client.Read(read_buf, kReadBufSize, NULL));
- EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), kTestDataSize));
+ int written = server.Write(write_buf, kTestDataSize, NULL);
+ EXPECT_GT(written, 0);
+ EXPECT_LE(written, kTestDataSize);
+
+ int read = client.Read(read_buf, kReadBufSize, NULL);
+ EXPECT_GT(read, 0);
+ EXPECT_LE(read, written);
+ EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read));
// Read then write.
TestCompletionCallback callback;
EXPECT_EQ(net::ERR_IO_PENDING,
server.Read(read_buf, kReadBufSize, &callback));
- EXPECT_EQ(kTestDataSize, client.Write(write_buf, kTestDataSize, NULL));
- EXPECT_EQ(kTestDataSize, callback.WaitForResult());
- EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), kTestDataSize));
+
+ written = client.Write(write_buf, kTestDataSize, NULL);
+ EXPECT_GT(written, 0);
+ EXPECT_LE(written, kTestDataSize);
+
+ read = callback.WaitForResult();
+ EXPECT_GT(read, 0);
+ EXPECT_LE(read, written);
+ EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read));
}
class SSLServerSocketTest : public PlatformTest {
« no previous file with comments | « net/socket/ssl_server_socket_nss.cc ('k') | remoting/protocol/jingle_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698