Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | |
|
Taylor Brandstetter
2017/03/07 18:16:32
2017
| |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "webrtc/p2p/base/packetlossestimator.h" | |
| 14 #include "webrtc/base/gunit.h" | |
| 15 | |
| 16 using cricket::PacketLossEstimator; | |
| 17 | |
| 18 static const std::pair<std::string, int64_t> kFivePackets[5] = {{"a", 0}, | |
| 19 {"b", 2}, | |
| 20 {"c", 4}, | |
| 21 {"d", 6}, | |
| 22 {"e", 8}}; | |
| 23 | |
| 24 class PacketLossEstimatorTest : public testing::Test {}; | |
| 25 | |
| 26 TEST_F(PacketLossEstimatorTest, InitialResponseRate) { | |
| 27 PacketLossEstimator ple(5, 100); | |
| 28 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 29 } | |
| 30 | |
| 31 TEST_F(PacketLossEstimatorTest, InitialUpdateResponseRate) { | |
| 32 PacketLossEstimator ple(5, 100); | |
| 33 ple.UpdateResponseRate(10); | |
| 34 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 35 } | |
| 36 | |
| 37 TEST_F(PacketLossEstimatorTest, ResponseReceived) { | |
| 38 PacketLossEstimator ple(5, 100); | |
| 39 | |
| 40 ple.ExpectResponse("a", 0); | |
| 41 ple.ReceivedResponse("a", 1); | |
| 42 ple.UpdateResponseRate(2); | |
| 43 | |
| 44 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 45 } | |
| 46 | |
| 47 TEST_F(PacketLossEstimatorTest, ResponseNotConsideredLostYet) { | |
| 48 PacketLossEstimator ple(5, 100); | |
| 49 | |
| 50 ple.ExpectResponse("a", 0); | |
| 51 ple.UpdateResponseRate(2); | |
| 52 | |
| 53 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 54 } | |
| 55 | |
| 56 TEST_F(PacketLossEstimatorTest, ResponseConsideredLost) { | |
| 57 PacketLossEstimator ple(5, 100); | |
| 58 | |
| 59 ple.ExpectResponse("a", 0); | |
| 60 ple.UpdateResponseRate(10); | |
| 61 | |
| 62 EXPECT_EQ(0.0, ple.get_response_rate()); | |
| 63 } | |
| 64 | |
| 65 TEST_F(PacketLossEstimatorTest, ResponseLate) { | |
| 66 PacketLossEstimator ple(5, 100); | |
| 67 | |
| 68 ple.ExpectResponse("a", 0); | |
| 69 ple.ReceivedResponse("a", 6); | |
| 70 ple.UpdateResponseRate(10); | |
| 71 | |
| 72 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 73 } | |
| 74 | |
| 75 TEST_F(PacketLossEstimatorTest, ResponseForgotten) { | |
| 76 PacketLossEstimator ple(5, 100); | |
| 77 ple.ExpectResponse("a", 0); | |
| 78 ple.UpdateResponseRate(101); | |
| 79 | |
| 80 EXPECT_EQ(1.0, ple.get_response_rate()); | |
| 81 } | |
| 82 | |
| 83 TEST_F(PacketLossEstimatorTest, Lost1_Received1) { | |
| 84 PacketLossEstimator ple(5, 100); | |
| 85 | |
| 86 ple.ExpectResponse("a", 0); | |
| 87 ple.ExpectResponse("b", 2); | |
| 88 ple.ReceivedResponse("b", 6); | |
| 89 ple.UpdateResponseRate(7); | |
| 90 | |
| 91 EXPECT_EQ(0.5, ple.get_response_rate()); | |
| 92 } | |
| 93 | |
| 94 // Time: 0 1 2 3 4 5 6 7 8 9 10 | |
| 95 // Sent: a b c d e | |
| 96 // Recv: b | |
| 97 // Wind: --------------> | |
| 98 TEST_F(PacketLossEstimatorTest, Lost3_Received1_Waiting1) { | |
|
Taylor Brandstetter
2017/03/07 18:16:32
Since these two tests depend on the contents of "k
| |
| 99 PacketLossEstimator ple(3, 100); | |
| 100 | |
| 101 for (const auto& p : kFivePackets) { | |
| 102 ple.ExpectResponse(p.first, p.second); | |
| 103 } | |
| 104 ple.ReceivedResponse("b", 3); | |
| 105 ple.UpdateResponseRate(10); | |
| 106 EXPECT_EQ(0.25, ple.get_response_rate()); | |
| 107 } | |
| 108 | |
| 109 // Time: 0 1 2 3 4 5 6 7 8 9 10 | |
| 110 // Sent: a b c d e | |
| 111 // Recv: c | |
| 112 // Wind: <-------> | |
| 113 TEST_F(PacketLossEstimatorTest, Forgot2_Received1_Lost1_Waiting1) { | |
| 114 PacketLossEstimator ple(3, 7); | |
| 115 | |
| 116 for (const auto& p : kFivePackets) { | |
| 117 ple.ExpectResponse(p.first, p.second); | |
| 118 } | |
| 119 ple.ReceivedResponse("c", 5); | |
| 120 ple.UpdateResponseRate(10); | |
| 121 EXPECT_EQ(0.5, ple.get_response_rate()); | |
| 122 } | |
| 123 | |
| 124 // If we do not ensure periodic calls to UpdateResponseRate internally, | |
| 125 // memory usage could grow without bound if the client never calls | |
| 126 // UpdateResponseRate manually. | |
| 127 TEST_F(PacketLossEstimatorTest, UpdateResponseRateIsCalledByExpectResponse) { | |
| 128 PacketLossEstimator ple(1, 5); | |
| 129 ple.ExpectResponse("a", 4); // This message will be lost. | |
| 130 ple.ExpectResponse("b", 6); // This call should trigger UpdateResponseRate. | |
| 131 EXPECT_EQ(0.0, ple.get_response_rate()); | |
| 132 } | |
| 133 | |
| 134 // If we do not ensure periodic calls to UpdateResponseRate internally, | |
| 135 // memory usage could grow without bound if the client never calls | |
| 136 // UpdateResponseRate manually. | |
| 137 TEST_F(PacketLossEstimatorTest, UpdateResponseRateIsCalledByReceivedResponse) { | |
| 138 PacketLossEstimator ple(1, 5); | |
| 139 ple.ExpectResponse("a", 4); // This message will be lost. | |
| 140 ple.ReceivedResponse("b", 6); // This call should trigger UpdateResponseRate. | |
| 141 EXPECT_EQ(0.0, ple.get_response_rate()); | |
| 142 } | |
| OLD | NEW |