ProcessUniqueIDTests.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  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. */
  16. import XCTest
  17. @testable import GRPCNIOTransportCore
  18. final class ProcessUniqueIDTests: XCTestCase {
  19. func testProcessUniqueIDIsUnique() {
  20. var ids: Set<ProcessUniqueID> = []
  21. for _ in 1 ... 100 {
  22. let (inserted, _) = ids.insert(ProcessUniqueID())
  23. XCTAssertTrue(inserted)
  24. }
  25. XCTAssertEqual(ids.count, 100)
  26. }
  27. func testProcessUniqueIDDescription() {
  28. let id = ProcessUniqueID()
  29. let description = String(describing: id)
  30. // We can't verify the exact description as we don't know what value to expect, we only
  31. // know that it'll be an integer.
  32. XCTAssertNotNil(UInt64(description))
  33. }
  34. func testSubchannelIDDescription() {
  35. let id = SubchannelID()
  36. let description = String(describing: id)
  37. XCTAssert(description.hasPrefix("subchan_"))
  38. }
  39. func testLoadBalancerIDDescription() {
  40. let id = LoadBalancerID()
  41. let description = String(describing: id)
  42. XCTAssert(description.hasPrefix("lb_"))
  43. }
  44. func testQueueEntryDescription() {
  45. let id = QueueEntryID()
  46. let description = String(describing: id)
  47. XCTAssert(description.hasPrefix("q_entry_"))
  48. }
  49. }