remove assertions
This commit is contained in:
parent
42372a8598
commit
2c58b010a2
|
|
@ -12,10 +12,6 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// MARK: Testing API
|
|
||||||
|
|
||||||
internal var _enableAssertions = true
|
|
||||||
|
|
||||||
// MARK: User API
|
// MARK: User API
|
||||||
|
|
||||||
extension Counter {
|
extension Counter {
|
||||||
|
|
@ -596,29 +592,18 @@ internal class AccumulatingRoundingFloatingPointCounter: FloatingPointCounterHan
|
||||||
}
|
}
|
||||||
|
|
||||||
func increment(by amount: Double) {
|
func increment(by amount: Double) {
|
||||||
// Drop values in illegal values (Asserting in debug builds)
|
// Drop illegal values
|
||||||
guard !amount.isNaN else {
|
// - cannot increment by NaN
|
||||||
assert(!_enableAssertions, "cannot increment by NaN")
|
guard !amount.isNaN else { return }
|
||||||
return
|
// - cannot increment by infinite quantities
|
||||||
}
|
guard !amount.isInfinite else { return }
|
||||||
|
// - cannot increment by negative values
|
||||||
|
guard amount.sign == .plus else { return }
|
||||||
|
// - cannot increment by zero
|
||||||
|
guard !amount.isZero else { return }
|
||||||
|
|
||||||
guard !amount.isInfinite else {
|
|
||||||
assert(!_enableAssertions, "cannot increment by infinite quantities")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard amount.sign == .plus else {
|
|
||||||
assert(!_enableAssertions, "cannot increment by negative values")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard !amount.isZero else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// If amount is in Int64.max..<+Inf
|
|
||||||
if amount.exponent >= 63 {
|
if amount.exponent >= 63 {
|
||||||
// Ceil to Int64.max
|
// If amount is in Int64.max..<+Inf, ceil to Int64.max
|
||||||
self.lock.withLockVoid {
|
self.lock.withLockVoid {
|
||||||
self.counterHandler.increment(by: .max)
|
self.counterHandler.increment(by: .max)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,63 +57,47 @@ class MetricsTests: XCTestCase {
|
||||||
// bootstrap with our test metrics
|
// bootstrap with our test metrics
|
||||||
let metrics = TestMetrics()
|
let metrics = TestMetrics()
|
||||||
MetricsSystem.bootstrapInternal(metrics)
|
MetricsSystem.bootstrapInternal(metrics)
|
||||||
// disable assertions to test fallback path
|
|
||||||
_enableAssertions = false
|
|
||||||
let label = "\(#function)-fp-counter-\(UUID())"
|
let label = "\(#function)-fp-counter-\(UUID())"
|
||||||
let fpCounter = FloatingPointCounter(label: label)
|
let fpCounter = FloatingPointCounter(label: label)
|
||||||
let counter = metrics.counters[label] as! TestCounter
|
let counter = metrics.counters[label] as! TestCounter
|
||||||
fpCounter.increment(by: Double.nan)
|
fpCounter.increment(by: Double.nan)
|
||||||
fpCounter.increment(by: Double.signalingNaN)
|
fpCounter.increment(by: Double.signalingNaN)
|
||||||
XCTAssertEqual(counter.values.count, 0, "expected nan values to be ignored")
|
XCTAssertEqual(counter.values.count, 0, "expected nan values to be ignored")
|
||||||
// reenable assertions
|
|
||||||
_enableAssertions = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultFloatingPointCounter_ignoresInfinity() throws {
|
func testDefaultFloatingPointCounter_ignoresInfinity() throws {
|
||||||
// bootstrap with our test metrics
|
// bootstrap with our test metrics
|
||||||
let metrics = TestMetrics()
|
let metrics = TestMetrics()
|
||||||
MetricsSystem.bootstrapInternal(metrics)
|
MetricsSystem.bootstrapInternal(metrics)
|
||||||
// disable assertions to test fallback path
|
|
||||||
_enableAssertions = false
|
|
||||||
let label = "\(#function)-fp-counter-\(UUID())"
|
let label = "\(#function)-fp-counter-\(UUID())"
|
||||||
let fpCounter = FloatingPointCounter(label: label)
|
let fpCounter = FloatingPointCounter(label: label)
|
||||||
let counter = metrics.counters[label] as! TestCounter
|
let counter = metrics.counters[label] as! TestCounter
|
||||||
fpCounter.increment(by: Double.infinity)
|
fpCounter.increment(by: Double.infinity)
|
||||||
fpCounter.increment(by: -Double.infinity)
|
fpCounter.increment(by: -Double.infinity)
|
||||||
XCTAssertEqual(counter.values.count, 0, "expected infinite values to be ignored")
|
XCTAssertEqual(counter.values.count, 0, "expected infinite values to be ignored")
|
||||||
// reenable assertions
|
|
||||||
_enableAssertions = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultFloatingPointCounter_ignoresNegativeValues() throws {
|
func testDefaultFloatingPointCounter_ignoresNegativeValues() throws {
|
||||||
// bootstrap with our test metrics
|
// bootstrap with our test metrics
|
||||||
let metrics = TestMetrics()
|
let metrics = TestMetrics()
|
||||||
MetricsSystem.bootstrapInternal(metrics)
|
MetricsSystem.bootstrapInternal(metrics)
|
||||||
// disable assertions to test fallback path
|
|
||||||
_enableAssertions = false
|
|
||||||
let label = "\(#function)-fp-counter-\(UUID())"
|
let label = "\(#function)-fp-counter-\(UUID())"
|
||||||
let fpCounter = FloatingPointCounter(label: label)
|
let fpCounter = FloatingPointCounter(label: label)
|
||||||
let counter = metrics.counters[label] as! TestCounter
|
let counter = metrics.counters[label] as! TestCounter
|
||||||
fpCounter.increment(by: -100)
|
fpCounter.increment(by: -100)
|
||||||
XCTAssertEqual(counter.values.count, 0, "expected negative values to be ignored")
|
XCTAssertEqual(counter.values.count, 0, "expected negative values to be ignored")
|
||||||
// reenable assertions
|
|
||||||
_enableAssertions = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultFloatingPointCounter_ignoresZero() throws {
|
func testDefaultFloatingPointCounter_ignoresZero() throws {
|
||||||
// bootstrap with our test metrics
|
// bootstrap with our test metrics
|
||||||
let metrics = TestMetrics()
|
let metrics = TestMetrics()
|
||||||
MetricsSystem.bootstrapInternal(metrics)
|
MetricsSystem.bootstrapInternal(metrics)
|
||||||
// disable assertions to test fallback path
|
|
||||||
_enableAssertions = false
|
|
||||||
let label = "\(#function)-fp-counter-\(UUID())"
|
let label = "\(#function)-fp-counter-\(UUID())"
|
||||||
let fpCounter = FloatingPointCounter(label: label)
|
let fpCounter = FloatingPointCounter(label: label)
|
||||||
let counter = metrics.counters[label] as! TestCounter
|
let counter = metrics.counters[label] as! TestCounter
|
||||||
fpCounter.increment(by: 0)
|
fpCounter.increment(by: 0)
|
||||||
fpCounter.increment(by: -0)
|
fpCounter.increment(by: -0)
|
||||||
XCTAssertEqual(counter.values.count, 0, "expected zero values to be ignored")
|
XCTAssertEqual(counter.values.count, 0, "expected zero values to be ignored")
|
||||||
// reenable assertions
|
|
||||||
_enableAssertions = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultFloatingPointCounter_ceilsExtremeValues() {
|
func testDefaultFloatingPointCounter_ceilsExtremeValues() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue