ProcessUniqueIDTests.swift 1.7 KB

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