@@ -3,12 +3,16 @@ package com.twitter.finagle.mux.lease.exp
3
3
import com .twitter .conversions .DurationOps ._
4
4
import com .twitter .util ._
5
5
import com .twitter .conversions .StorageUnitOps ._
6
- import org .scalatest .concurrent .{Eventually , IntegrationPatience }
6
+ import org .scalatest .concurrent .Eventually
7
+ import org .scalatest .concurrent .IntegrationPatience
7
8
import scala .util .Random
9
+ import org .scalactic .Tolerance ._
8
10
import org .scalatest .funsuite .AnyFunSuite
9
11
10
12
class WindowedByteCounterTest extends AnyFunSuite with Eventually with IntegrationPatience {
11
13
14
+ private [this ] val epsilon = 1e-3
15
+
12
16
trait ByteCounterHelper {
13
17
val fakePool = new FakeMemoryPool (new FakeMemoryUsage (StorageUnit .zero, StorageUnit .zero))
14
18
val fakeBean = new FakeGarbageCollectorMXBean (0 , 0 )
@@ -93,9 +97,9 @@ class WindowedByteCounterTest extends AnyFunSuite with Eventually with Integrati
93
97
nextPeriod()
94
98
}
95
99
96
- assert(
97
- counter.rate() == ( WindowedByteCounter .N .kilobytes) .inBytes / WindowedByteCounter .W .inMilliseconds
98
- )
100
+ val expectedRate =
101
+ WindowedByteCounter .N .kilobytes.inBytes / WindowedByteCounter .W .inMilliseconds.toDouble
102
+ assert(counter.rate() === expectedRate +- epsilon )
99
103
}
100
104
}
101
105
@@ -111,9 +115,9 @@ class WindowedByteCounterTest extends AnyFunSuite with Eventually with Integrati
111
115
nextPeriod()
112
116
}
113
117
114
- assert(
115
- counter.rate() == ( WindowedByteCounter .N .kilobytes) .inBytes / WindowedByteCounter .W .inMilliseconds
116
- )
118
+ val expectedRate1 =
119
+ WindowedByteCounter .N .kilobytes.inBytes / WindowedByteCounter .W .inMilliseconds.toDouble
120
+ assert(counter.rate() === expectedRate1 +- epsilon )
117
121
118
122
for (i <- 1 to WindowedByteCounter .N ) {
119
123
fakePool.setSnapshot(
@@ -122,10 +126,9 @@ class WindowedByteCounterTest extends AnyFunSuite with Eventually with Integrati
122
126
nextPeriod()
123
127
}
124
128
125
- assert(
126
- counter
127
- .rate() == (2 * (WindowedByteCounter .N .kilobytes).inBytes / WindowedByteCounter .W .inMilliseconds)
128
- )
129
+ val expectedRate2 =
130
+ 2 * WindowedByteCounter .N .kilobytes.inBytes / WindowedByteCounter .W .inMilliseconds.toDouble
131
+ assert(counter.rate() === expectedRate2 +- epsilon)
129
132
}
130
133
}
131
134
@@ -145,7 +148,8 @@ class WindowedByteCounterTest extends AnyFunSuite with Eventually with Integrati
145
148
nextPeriod()
146
149
}
147
150
148
- assert(counter.rate() == x.inBytes / WindowedByteCounter .W .inMilliseconds)
151
+ val expectedRate = x.inBytes / WindowedByteCounter .W .inMilliseconds.toDouble
152
+ assert(counter.rate() === expectedRate +- epsilon)
149
153
}
150
154
}
151
155
@@ -176,9 +180,9 @@ class WindowedByteCounterTest extends AnyFunSuite with Eventually with Integrati
176
180
nextPeriod()
177
181
}
178
182
179
- assert(
180
- counter.rate() == WindowedByteCounter .N .kilobytes.inBytes / WindowedByteCounter .W .inMilliseconds
181
- )
183
+ val expectedRate =
184
+ WindowedByteCounter .N .kilobytes.inBytes / WindowedByteCounter .W .inMilliseconds.toDouble
185
+ assert(counter.rate() === expectedRate +- epsilon )
182
186
}
183
187
}
184
188
0 commit comments