Adding the ability to use a simulated clock for unit tests.

This will be useful for any tests that test objects with time-dependent
behavior. It will allow such tests to be written in such a way that their
outcome is more repeatable (less flaky), and will also allow such tests
to finish quicker. For example, a test for STUN timeout doesn't need to
wait the full timeout interval in real time; it can simply advance the
simulated clock.

BUG=webrtc:4925
R=pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/1895933003 .

Cr-Commit-Position: refs/heads/master@{#12950}
This commit is contained in:
Taylor Brandstetter
2016-05-27 14:15:43 -07:00
parent 1c20610ede
commit b3c6810be3
10 changed files with 460 additions and 9 deletions

View File

@ -37,7 +37,7 @@ class MessageQueue;
// MessageQueueManager does cleanup of of message queues
class MessageQueueManager {
class MessageQueueManager : public MessageHandler {
public:
static void Add(MessageQueue *message_queue);
static void Remove(MessageQueue *message_queue);
@ -49,15 +49,22 @@ class MessageQueueManager {
// MessageQueueManager instance when necessary.
static bool IsInitialized();
// Mainly for testing purposes, for use with a simulated clock.
// Posts a no-op event on all message queues so they will wake from the
// socket server select() and process messages again.
static void WakeAllMessageQueues();
private:
static MessageQueueManager* Instance();
MessageQueueManager();
~MessageQueueManager();
~MessageQueueManager() override;
void AddInternal(MessageQueue *message_queue);
void RemoveInternal(MessageQueue *message_queue);
void ClearInternal(MessageHandler *handler);
void WakeAllMessageQueuesInternal();
void OnMessage(Message* pmsg) override;
static MessageQueueManager* instance_;
// This list contains all live MessageQueues.