Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(152)

Delta Between Two Patch Sets: Src/GoogleApis.Tests/Apis/Utils/ExponentialBackOffTest.cs

Issue 12566043: Issue 369: Change default behavior of an HTTP request (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 10 years, 7 months ago
Right Patch Set: Miceli review Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 Copyright 2013 Google Inc 2 Copyright 2013 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // invalid delta 56 // invalid delta
57 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(-1)); 57 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(-1));
58 SubtestConstructor_InvalidValue(TimeSpan.FromDays(-1)); 58 SubtestConstructor_InvalidValue(TimeSpan.FromDays(-1));
59 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(1001)); 59 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(1001));
60 // invalid max 60 // invalid max
61 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(500), -1); 61 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(500), -1);
62 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(500), 21); 62 SubtestConstructor_InvalidValue(TimeSpan.FromMilliseconds(500), 21);
63 63
64 } 64 }
65 65
66 /// <summary> An helper subtest to test invalid value given to the const ructor. </summary> 66 /// <summary> A helper subtest to test invalid value given to the constr uctor. </summary>
67 private void SubtestConstructor_InvalidValue(TimeSpan ts, int max = 10) 67 private void SubtestConstructor_InvalidValue(TimeSpan ts, int max = 10)
68 { 68 {
69 try 69 try
70 { 70 {
71 ExponentialBackOff backOff = new ExponentialBackOff(ts, max); 71 ExponentialBackOff backOff = new ExponentialBackOff(ts, max);
72 Assert.Fail(); 72 Assert.Fail();
73 } 73 }
74 catch (ArgumentOutOfRangeException) { } 74 catch (ArgumentOutOfRangeException) { }
75 } 75 }
76 76
(...skipping 29 matching lines...) Expand all
106 { 106 {
107 var ts = backOff.GetNextBackOff(retry); 107 var ts = backOff.GetNextBackOff(retry);
108 Assert.That(ts, Is.InRange(min, max)); 108 Assert.That(ts, Is.InRange(min, max));
109 total += (int)ts.TotalMilliseconds; 109 total += (int)ts.TotalMilliseconds;
110 } 110 }
111 111
112 var avarage = (int)(total / repeat); 112 var avarage = (int)(total / repeat);
113 Assert.That(avarage, Is.InRange(expectedMiliis - epsilon, expectedMi liis + epsilon)); 113 Assert.That(avarage, Is.InRange(expectedMiliis - epsilon, expectedMi liis + epsilon));
114 } 114 }
115 115
116
117 /// <summary> Tests next back-off time span with specific maximum of ret ries. </summary> 116 /// <summary> Tests next back-off time span with specific maximum of ret ries. </summary>
118 [Test] 117 [Test]
119 public void GetNextBackOff_MaxNumRetries() 118 public void GetNextBackOff_MaxNumRetries()
120 { 119 {
121 SubtestGetNextBackOff_MaxNumRetries(1); 120 SubtestGetNextBackOff_MaxNumRetries(1);
122 SubtestGetNextBackOff_MaxNumRetries(10); 121 SubtestGetNextBackOff_MaxNumRetries(10);
123 SubtestGetNextBackOff_MaxNumRetries(11); 122 SubtestGetNextBackOff_MaxNumRetries(11);
124 } 123 }
125 124
126 /// <summary> An helper test for testing the <c>GetNextBackOff</c> logic . </summary> 125 /// <summary> A helper test for testing the <c>GetNextBackOff</c> logic. </summary>
ngmiceli 2013/08/13 19:31:26 A helper, not "an" :)
peleyal 2013/08/13 21:46:20 Done.
127 private void SubtestGetNextBackOff_MaxNumRetries(int max) 126 private void SubtestGetNextBackOff_MaxNumRetries(int max)
128 { 127 {
129 ExponentialBackOff backOff = new ExponentialBackOff(TimeSpan.Zero, m ax); 128 ExponentialBackOff backOff = new ExponentialBackOff(TimeSpan.Zero, m ax);
130 129
131 for (int i = 1; i <= 10; ++i) 130 for (int i = 1; i <= 10; ++i)
132 { 131 {
133 if (i <= max) 132 if (i <= max)
134 { 133 {
135 Assert.AreNotEqual(TimeSpan.MinValue, backOff.GetNextBackOff (i)); 134 Assert.AreNotEqual(TimeSpan.MinValue, backOff.GetNextBackOff (i));
136 } 135 }
137 else 136 else
138 { 137 {
139 Assert.AreEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i) ); 138 Assert.AreEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i) );
140 } 139 }
141 } 140 }
142 } 141 }
143 } 142 }
144 } 143 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b