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

Side by Side Diff: chromecast/crash/linux/minidump_writer_unittest.cc

Issue 1310313004: [Chromecast] Move SynchronizedMinidumpManager ratelimit logic to child classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Clarify comment on test functions. Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | chromecast/crash/linux/synchronized_minidump_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fstream> 5 #include <fstream>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 TEST_F(MinidumpWriterTest, Write_FailsWithSubdirInCorrectPath) { 116 TEST_F(MinidumpWriterTest, Write_FailsWithSubdirInCorrectPath) {
117 MinidumpWriter writer(&fake_generator_, 117 MinidumpWriter writer(&fake_generator_,
118 dumplog_file_.Append("subdir/logfile").value(), 118 dumplog_file_.Append("subdir/logfile").value(),
119 MinidumpParams(), 119 MinidumpParams(),
120 base::Bind(&FakeDumpState)); 120 base::Bind(&FakeDumpState));
121 ASSERT_EQ(-1, writer.Write()); 121 ASSERT_EQ(-1, writer.Write());
122 } 122 }
123 123
124 TEST_F(MinidumpWriterTest, Write_FailsWhenTooManyDumpsPresent) {
125 MinidumpWriter writer(&fake_generator_,
126 dumplog_file_.value(),
127 MinidumpParams(),
128 base::Bind(&FakeDumpState));
129
130 // Write dump logs to the lockfile.
131 size_t too_many_dumps = SynchronizedMinidumpManager::kMaxLockfileDumps + 1;
132 for (size_t i = 0; i < too_many_dumps; ++i) {
133 scoped_ptr<DumpInfo> info(CreateDumpInfo(
134 "{"
135 "\"name\": \"p\","
136 "\"dump_time\" : \"2012-01-01 01:02:03\","
137 "\"dump\": \"dump_string\","
138 "\"uptime\": \"123456789\","
139 "\"logfile\": \"logfile.log\""
140 "}"));
141 ASSERT_TRUE(info->valid());
142 ASSERT_TRUE(AppendLockFile(*info));
143 }
144
145 ASSERT_EQ(-1, writer.Write());
146 }
147
148 TEST_F(MinidumpWriterTest, Write_FailsWhenTooManyRecentDumpsPresent) {
149 MinidumpWriter writer(&fake_generator_,
150 dumplog_file_.value(),
151 MinidumpParams(),
152 base::Bind(&FakeDumpState));
153 // Multiple iters to make sure period resets work correctly
154 for (int iter = 0; iter < 3; ++iter) {
155 time_t now = time(nullptr);
156
157 // Write dump logs to the lockfile.
158 size_t too_many_recent_dumps =
159 SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps;
160 for (size_t i = 0; i < too_many_recent_dumps; ++i) {
161 ASSERT_EQ(0, writer.Write());
162
163 // Clear dumps so we don't reach max dumps in lockfile
164 ASSERT_TRUE(ClearDumps(lockfile_path_.value()));
165 }
166
167 // Should fail with too many dumps
168 ASSERT_EQ(-1, writer.Write());
169
170 int64 period = SynchronizedMinidumpManager::kRatelimitPeriodSeconds;
171
172 // Half period shouldn't trigger reset
173 SetRatelimitPeriodStart(metadata_path_.value(), now - period / 2);
174 ASSERT_EQ(-1, writer.Write());
175
176 // Set period starting time to trigger a reset
177 SetRatelimitPeriodStart(metadata_path_.value(), now - period);
178 }
179
180 ASSERT_EQ(0, writer.Write());
181 }
182
183 TEST_F(MinidumpWriterTest, Write_SucceedsWhenDumpLimitsNotExceeded) {
184 MinidumpWriter writer(&fake_generator_,
185 dumplog_file_.value(),
186 MinidumpParams(),
187 base::Bind(&FakeDumpState));
188
189 ASSERT_GT(SynchronizedMinidumpManager::kMaxLockfileDumps, 1);
190 ASSERT_GT(SynchronizedMinidumpManager::kRatelimitPeriodMaxDumps, 0);
191
192 // Write an old dump logs to the lockfile.
193 scoped_ptr<DumpInfo> info(CreateDumpInfo(
194 "{"
195 "\"name\": \"p\","
196 "\"dump_time\" : \"2012-01-01 01:02:03\","
197 "\"dump\": \"dump_string\","
198 "\"uptime\": \"123456789\","
199 "\"logfile\": \"logfile.log\""
200 "}"));
201 ASSERT_TRUE(info->valid());
202 ASSERT_TRUE(AppendLockFile(*info));
203 ASSERT_EQ(0, writer.Write());
204 }
205
206 } // namespace chromecast 124 } // namespace chromecast
OLDNEW
« no previous file with comments | « no previous file | chromecast/crash/linux/synchronized_minidump_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698