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

Unified Diff: sync/engine/traffic_recorder_unittest.cc

Issue 9732008: [Sync] Store the past 10 traffic records in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 9 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
Index: sync/engine/traffic_recorder_unittest.cc
diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc
new file mode 100755
index 0000000000000000000000000000000000000000..1ee9cbc2aaf45e808806455ba6badb148c8de2f3
--- /dev/null
+++ b/sync/engine/traffic_recorder_unittest.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/engine/traffic_recorder.h"
+
+#include "sync/protocol/sync.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser_sync {
+
+const unsigned int kMaxMessages = 10;
+const unsigned int kMaxMessageSize = 5 * 1024;
+
+// Ensure the number of records don't exceed |kMaxMessages|.
+TEST(TrafficRecorderTest, MaxRecordsTest) {
+ TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
+ sync_pb::ClientToServerResponse response;
+
+ for (unsigned int i = 0; i<2*kMaxMessages; ++i)
akalin 2012/03/29 19:46:36 spaces around '<'
lipalani1 2012/03/30 00:33:24 Done.
+ recorder.RecordClientToServerResponse(response);
+
+ EXPECT_EQ(recorder.records().size(), kMaxMessages);
+}
+
+// Ensure records with size greater than |kMaxMessageSize| are truncated.
+TEST(TrafficRecorderTest, MaxMessageSizeTest) {
+ sync_pb::ClientToServerResponse response;
+
+ sync_pb::ClientToServerResponse::Error* error = response.mutable_error();
+ std::string error_description(kMaxMessageSize * 2, 'a');
+ error->set_error_description(error_description);
+
+ TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
+ recorder.RecordClientToServerResponse(response);
+
+ TrafficRecorder::TrafficRecord record = recorder.records().front();
+ EXPECT_TRUE(record.truncated);
+ EXPECT_TRUE(record.message.empty());
+}
+
+} //namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698