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

Unified Diff: remoting/protocol/jingle_session_unittest.cc

Issue 7275024: PseudoTcp to expose settings of nagling and ACK delay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« jingle/glue/pseudotcp_adapter.h ('K') | « remoting/protocol/jingle_session.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/jingle_session_unittest.cc
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
index 003fcfd21532ae900c253927c09094b22ee9bbab..ffdfcc5487de300ff4d6b963482776a5ad1cb213 100644
--- a/remoting/protocol/jingle_session_unittest.cc
+++ b/remoting/protocol/jingle_session_unittest.cc
@@ -323,14 +323,18 @@ class TCPChannelTester : public ChannelTesterBase {
public:
TCPChannelTester(MessageLoop* message_loop,
Session* host_session,
- Session* client_session)
+ Session* client_session,
+ int message_size, int message_count)
: ChannelTesterBase(message_loop, host_session, client_session),
ALLOW_THIS_IN_INITIALIZER_LIST(
write_cb_(this, &TCPChannelTester::OnWritten)),
ALLOW_THIS_IN_INITIALIZER_LIST(
read_cb_(this, &TCPChannelTester::OnRead)),
write_errors_(0),
- read_errors_(0) {
+ read_errors_(0),
+ message_size_(message_size),
+ message_count_(message_count),
+ test_data_size_(message_size * message_count) {
}
virtual ~TCPChannelTester() { }
@@ -339,24 +343,24 @@ class TCPChannelTester : public ChannelTesterBase {
EXPECT_EQ(0, write_errors_);
EXPECT_EQ(0, read_errors_);
- ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity());
+ ASSERT_EQ(test_data_size_ + message_size_, input_buffer_->capacity());
output_buffer_->SetOffset(0);
- ASSERT_EQ(kTestDataSize, output_buffer_->size());
+ ASSERT_EQ(test_data_size_, output_buffer_->size());
EXPECT_EQ(0, memcmp(output_buffer_->data(),
- input_buffer_->StartOfBuffer(), kTestDataSize));
+ input_buffer_->StartOfBuffer(), test_data_size_));
}
protected:
virtual void InitBuffers() {
output_buffer_ = new net::DrainableIOBuffer(
- new net::IOBuffer(kTestDataSize), kTestDataSize);
- memset(output_buffer_->data(), 123, kTestDataSize);
+ new net::IOBuffer(test_data_size_), test_data_size_);
+ memset(output_buffer_->data(), 123, test_data_size_);
input_buffer_ = new net::GrowableIOBuffer();
- // Always keep kMessageSize bytes available at the end of the input buffer.
- input_buffer_->SetCapacity(kMessageSize);
+ // Always keep message_size_ bytes available at the end of the input buffer.
+ input_buffer_->SetCapacity(message_size_);
}
virtual void DoWrite() {
@@ -366,7 +370,7 @@ class TCPChannelTester : public ChannelTesterBase {
break;
int bytes_to_write = std::min(output_buffer_->BytesRemaining(),
- kMessageSize);
+ message_size_);
result = socket_1_->Write(output_buffer_, bytes_to_write, &write_cb_);
HandleWriteResult(result);
};
@@ -390,9 +394,9 @@ class TCPChannelTester : public ChannelTesterBase {
virtual void DoRead() {
int result = 1;
while (result > 0) {
- input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize);
+ input_buffer_->set_offset(input_buffer_->capacity() - message_size_);
- result = socket_2_->Read(input_buffer_, kMessageSize, &read_cb_);
+ result = socket_2_->Read(input_buffer_, message_size_, &read_cb_);
HandleReadResult(result);
};
}
@@ -413,12 +417,11 @@ class TCPChannelTester : public ChannelTesterBase {
} else if (result > 0) {
// Allocate memory for the next read.
input_buffer_->SetCapacity(input_buffer_->capacity() + result);
- if (input_buffer_->capacity() == kTestDataSize + kMessageSize)
+ if (input_buffer_->capacity() == test_data_size_ + message_size_)
done_event_.Signal();
}
}
- private:
scoped_refptr<net::DrainableIOBuffer> output_buffer_;
scoped_refptr<net::GrowableIOBuffer> input_buffer_;
@@ -426,6 +429,39 @@ class TCPChannelTester : public ChannelTesterBase {
net::CompletionCallbackImpl<TCPChannelTester> read_cb_;
int write_errors_;
int read_errors_;
+ int message_size_;
+ int message_count_;
+ int test_data_size_;
+};
+
+class ChannelLatencyTester : public TCPChannelTester {
+ public:
+ ChannelLatencyTester(MessageLoop* message_loop,
+ Session* host_session,
+ Session* client_session,
+ int message_size)
+ : TCPChannelTester(message_loop, host_session,
+ client_session, message_size, 1) {
+ CHECK(message_size >= 8);
+ }
+
+ virtual ~ChannelLatencyTester() { }
+
+ virtual void CheckResults() {
+ }
+
+ base::TimeDelta GetLatency() {
+ return base::Time::Now() - start_time_;
+ }
+
+ protected:
+ virtual void InitBuffers() {
+ TCPChannelTester::InitBuffers();
+
+ start_time_ = base::Time::Now();
+ }
+
+ base::Time start_time_;
};
class UDPChannelTester : public ChannelTesterBase {
@@ -606,7 +642,7 @@ TEST_F(JingleSessionTest, TestControlChannel) {
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(
new TCPChannelTester(thread_.message_loop(), host_session_,
- client_session_));
+ client_session_, kMessageSize, kMessages));
tester->Start(ChannelTesterBase::CONTROL);
ASSERT_TRUE(tester->WaitFinished());
tester->CheckResults();
@@ -621,7 +657,7 @@ TEST_F(JingleSessionTest, TestVideoChannel) {
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(
new TCPChannelTester(thread_.message_loop(), host_session_,
- client_session_));
+ client_session_, kMessageSize, kMessageSize));
tester->Start(ChannelTesterBase::VIDEO);
ASSERT_TRUE(tester->WaitFinished());
tester->CheckResults();
@@ -636,7 +672,7 @@ TEST_F(JingleSessionTest, TestEventChannel) {
ASSERT_TRUE(InitiateConnection());
scoped_refptr<TCPChannelTester> tester(
new TCPChannelTester(thread_.message_loop(), host_session_,
- client_session_));
+ client_session_, kMessageSize, kMessageSize));
tester->Start(ChannelTesterBase::EVENT);
ASSERT_TRUE(tester->WaitFinished());
tester->CheckResults();
@@ -660,6 +696,43 @@ TEST_F(JingleSessionTest, TestVideoRtpChannel) {
CloseSessions();
}
+TEST_F(JingleSessionTest, TestLatency) {
Sergey Ulanov 2011/06/28 18:34:26 Add comment that explain what this test verifies.
+ CreateServerPair();
+ ASSERT_TRUE(InitiateConnection());
+ scoped_refptr<ChannelLatencyTester> tester;
+
+ tester = new ChannelLatencyTester(thread_.message_loop(), host_session_,
+ client_session_, 512);
+ tester->Start(ChannelTesterBase::VIDEO);
+ ASSERT_TRUE(tester->WaitFinished());
+ LOG(INFO) << "Latency for 512 bytes "
+ << tester->GetLatency().InMilliseconds() << " ms.";
+
+ tester = new ChannelLatencyTester(thread_.message_loop(), host_session_,
+ client_session_, 1024);
+ tester->Start(ChannelTesterBase::VIDEO);
+ ASSERT_TRUE(tester->WaitFinished());
+ LOG(INFO) << "Latency for 1024 bytes "
+ << tester->GetLatency().InMilliseconds() << " ms.";
+
+ tester = new ChannelLatencyTester(thread_.message_loop(), host_session_,
+ client_session_, 51200);
+ tester->Start(ChannelTesterBase::VIDEO);
+ ASSERT_TRUE(tester->WaitFinished());
+ LOG(INFO) << "Latency for 50k bytes "
+ << tester->GetLatency().InMilliseconds() << " ms.";
+
+ tester = new ChannelLatencyTester(thread_.message_loop(), host_session_,
+ client_session_, 512000);
+ tester->Start(ChannelTesterBase::VIDEO);
+ ASSERT_TRUE(tester->WaitFinished());
+ LOG(INFO) << "Latency for 500k bytes "
+ << tester->GetLatency().InMilliseconds() << " ms.";
+
+ // Connections must be closed while |tester| still exists.
+ CloseSessions();
+}
+
#endif
} // namespace protocol
« jingle/glue/pseudotcp_adapter.h ('K') | « remoting/protocol/jingle_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698