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

Side by Side Diff: cc/scheduler/delay_based_time_source_unittest.cc

Issue 22887010: cc: Handle future timebases properly in DelayBasedTimeSource (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nix extraneous epsilon Created 7 years, 4 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/scheduler/delay_based_time_source.h" 5 #include "cc/scheduler/delay_based_time_source.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "cc/test/scheduler_test_common.h" 9 #include "cc/test/scheduler_test_common.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 client.Reset(); 299 client.Reset();
300 task_runner->ClearPendingTasks(); 300 task_runner->ClearPendingTasks();
301 task_runner->RunPendingTasks(); 301 task_runner->RunPendingTasks();
302 timer->SetTimebaseAndInterval(base::TimeTicks() + Interval() * 3, Interval()); 302 timer->SetTimebaseAndInterval(base::TimeTicks() + Interval() * 3, Interval());
303 303
304 EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled. 304 EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled.
305 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds()); 305 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
306 } 306 }
307 307
308 TEST(DelayBasedTimeSource, JitteryRuntimeWithFutureTimebases) {
309 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
310 new base::TestSimpleTaskRunner;
311 FakeTimeSourceClient client;
312 scoped_refptr<FakeDelayBasedTimeSource> timer =
313 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
314 timer->SetClient(&client);
315 timer->SetActive(true);
316
317 // Run the first tick.
318 task_runner->RunPendingTasks();
319 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
320
321 base::TimeTicks future_timebase = timer->Now() + Interval() * 10;
322
323 // 1ms jitter
324 base::TimeDelta jitter1 = base::TimeDelta::FromMilliseconds(1);
325
326 // Tick with +1ms of jitter
327 future_timebase += Interval();
328 timer->SetTimebaseAndInterval(future_timebase, Interval());
329 timer->SetNow(timer->Now() + Interval() + jitter1);
330 task_runner->RunPendingTasks();
331 EXPECT_EQ(15, task_runner->NextPendingTaskDelay().InMilliseconds());
332
333 // Tick with 0ms of jitter
334 future_timebase += Interval();
335 timer->SetTimebaseAndInterval(future_timebase, Interval());
336 timer->SetNow(timer->Now() + Interval() - jitter1);
337 task_runner->RunPendingTasks();
338 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
339
340 // Tick with -1ms of jitter
341 future_timebase += Interval();
342 timer->SetTimebaseAndInterval(future_timebase, Interval());
343 timer->SetNow(timer->Now() + Interval() - jitter1);
344 task_runner->RunPendingTasks();
345 EXPECT_EQ(17, task_runner->NextPendingTaskDelay().InMilliseconds());
346
347 // Tick with 0ms of jitter
348 future_timebase += Interval();
349 timer->SetTimebaseAndInterval(future_timebase, Interval());
350 timer->SetNow(timer->Now() + Interval() + jitter1);
351 task_runner->RunPendingTasks();
352 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
353
354 // 8 ms jitter
355 base::TimeDelta jitter8 = base::TimeDelta::FromMilliseconds(8);
356
357 // Tick with +8ms of jitter
358 future_timebase += Interval();
359 timer->SetTimebaseAndInterval(future_timebase, Interval());
360 timer->SetNow(timer->Now() + Interval() + jitter8);
361 task_runner->RunPendingTasks();
362 EXPECT_EQ(8, task_runner->NextPendingTaskDelay().InMilliseconds());
363
364 // Tick with 0ms of jitter
365 future_timebase += Interval();
366 timer->SetTimebaseAndInterval(future_timebase, Interval());
367 timer->SetNow(timer->Now() + Interval() - jitter8);
368 task_runner->RunPendingTasks();
369 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
370
371 // Tick with -8ms of jitter
372 future_timebase += Interval();
373 timer->SetTimebaseAndInterval(future_timebase, Interval());
374 timer->SetNow(timer->Now() + Interval() - jitter8);
375 task_runner->RunPendingTasks();
376 EXPECT_EQ(24, task_runner->NextPendingTaskDelay().InMilliseconds());
377
378 // Tick with 0ms of jitter
379 future_timebase += Interval();
380 timer->SetTimebaseAndInterval(future_timebase, Interval());
381 timer->SetNow(timer->Now() + Interval() + jitter8);
382 task_runner->RunPendingTasks();
383 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
384
385 // 15 ms jitter
386 base::TimeDelta jitter15 = base::TimeDelta::FromMilliseconds(15);
387
388 // Tick with +15ms jitter
389 future_timebase += Interval();
390 timer->SetTimebaseAndInterval(future_timebase, Interval());
391 timer->SetNow(timer->Now() + Interval() + jitter15);
392 task_runner->RunPendingTasks();
393 EXPECT_EQ(1, task_runner->NextPendingTaskDelay().InMilliseconds());
394
395 // Tick with 0ms of jitter
396 future_timebase += Interval();
397 timer->SetTimebaseAndInterval(future_timebase, Interval());
398 timer->SetNow(timer->Now() + Interval() - jitter15);
399 task_runner->RunPendingTasks();
400 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
401
402 // Tick with -15ms of jitter
403 future_timebase += Interval();
404 timer->SetTimebaseAndInterval(future_timebase, Interval());
405 timer->SetNow(timer->Now() + Interval() - jitter15);
406 task_runner->RunPendingTasks();
407 EXPECT_EQ(31, task_runner->NextPendingTaskDelay().InMilliseconds());
408
409 // Tick with 0ms of jitter
410 future_timebase += Interval();
411 timer->SetTimebaseAndInterval(future_timebase, Interval());
412 timer->SetNow(timer->Now() + Interval() + jitter15);
413 task_runner->RunPendingTasks();
414 EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
415 }
416
308 TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) { 417 TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) {
309 int num_iterations = 10; 418 int num_iterations = 10;
310 419
311 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 420 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
312 new base::TestSimpleTaskRunner; 421 new base::TestSimpleTaskRunner;
313 FakeTimeSourceClient client; 422 FakeTimeSourceClient client;
314 scoped_refptr<FakeDelayBasedTimeSource> timer = 423 scoped_refptr<FakeDelayBasedTimeSource> timer =
315 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); 424 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
316 timer->SetClient(&client); 425 timer->SetClient(&client);
317 timer->SetActive(true); 426 timer->SetActive(true);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 501
393 // Start the timer again, but before the next tick time the timer previously 502 // Start the timer again, but before the next tick time the timer previously
394 // planned on using. That same tick time should still be targeted. 503 // planned on using. That same tick time should still be targeted.
395 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); 504 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20));
396 timer->SetActive(true); 505 timer->SetActive(true);
397 EXPECT_EQ(13, task_runner->NextPendingTaskDelay().InMilliseconds()); 506 EXPECT_EQ(13, task_runner->NextPendingTaskDelay().InMilliseconds());
398 } 507 }
399 508
400 } // namespace 509 } // namespace
401 } // namespace cc 510 } // namespace cc
OLDNEW
« cc/scheduler/delay_based_time_source.cc ('K') | « cc/scheduler/delay_based_time_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698