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

Side by Side Diff: 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/
Patch Set: Miceli review Created 11 years, 3 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:
View unified diff | Download patch
OLDNEW
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 public void SubtestGetNextBackOff_MaxNumRetries(int max) 125 /// <summary> A helper test for testing the <c>GetNextBackOff</c> logic. </summary>
126 private void SubtestGetNextBackOff_MaxNumRetries(int max)
127 { 127 {
128 ExponentialBackOff backOff = new ExponentialBackOff(TimeSpan.Zero, m ax); 128 ExponentialBackOff backOff = new ExponentialBackOff(TimeSpan.Zero, m ax);
129 129
130 for (int i = 1; i <= 10; ++i) 130 for (int i = 1; i <= 10; ++i)
131 { 131 {
132 if (i <= max) 132 if (i <= max)
133 { 133 {
134 Assert.AreNotEqual(TimeSpan.MinValue, backOff.GetNextBackOff (i)); 134 Assert.AreNotEqual(TimeSpan.MinValue, backOff.GetNextBackOff (i));
135 } 135 }
136 else 136 else
137 { 137 {
138 Assert.AreEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i) ); 138 Assert.AreEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i) );
139 } 139 }
140 } 140 }
141 } 141 }
142 } 142 }
143 } 143 }
OLDNEW

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