SessionSamplerTests.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (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
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. import XCTest
  16. @testable import FirebaseSessions
  17. class SessionSamplerTests: XCTestCase {
  18. /// Validates if the default sampling rate is to allow all events.
  19. func test_defaultSamplingRate() {
  20. let localSampler = SessionSampler()
  21. XCTAssertEqual(localSampler.sessionSamplingRate, 1.0)
  22. }
  23. /// Validates if the events are disabled when the sampling rate is Zero.
  24. func test_disablesEventCollection_samplingRateZero() {
  25. let localSampler = SessionSampler(sessionSamplingRate: 0.0)
  26. XCTAssertEqual(localSampler.shouldSendEventForSession(sessionId: "random"), false)
  27. XCTAssertEqual(localSampler.shouldSendEventForSession(sessionId: "anyEvent"), false)
  28. }
  29. /// Validates if the events are allowed when the sampling rate is One.
  30. func test_allowsEventCollection_samplingRateOne() {
  31. let localSampler = SessionSampler(sessionSamplingRate: 1.0)
  32. XCTAssertEqual(localSampler.shouldSendEventForSession(sessionId: "random"), true)
  33. XCTAssertEqual(localSampler.shouldSendEventForSession(sessionId: "anyEvent"), true)
  34. }
  35. }