DelegatingErrorHandlerTests.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2019, 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. #if canImport(NIOSSL)
  17. import Foundation
  18. @testable import GRPC
  19. import Logging
  20. import NIOCore
  21. import NIOEmbedded
  22. import NIOSSL
  23. import XCTest
  24. class DelegatingErrorHandlerTests: GRPCTestCase {
  25. final class ErrorRecorder: ClientErrorDelegate {
  26. var errors: [Error] = []
  27. init() {}
  28. func didCatchError(_ error: Error, logger: Logger, file: StaticString, line: Int) {
  29. self.errors.append(error)
  30. }
  31. }
  32. func testUncleanShutdownIsIgnored() throws {
  33. let delegate = ErrorRecorder()
  34. let channel =
  35. EmbeddedChannel(handler: DelegatingErrorHandler(logger: self.logger, delegate: delegate))
  36. channel.pipeline.fireErrorCaught(NIOSSLError.uncleanShutdown)
  37. channel.pipeline.fireErrorCaught(NIOSSLError.writeDuringTLSShutdown)
  38. XCTAssertEqual(delegate.errors.count, 1)
  39. XCTAssertEqual(delegate.errors[0] as? NIOSSLError, .writeDuringTLSShutdown)
  40. }
  41. }
  42. // Unchecked because the error recorder is only ever used in the context of an EmbeddedChannel.
  43. extension DelegatingErrorHandlerTests.ErrorRecorder: @unchecked Sendable {}
  44. #endif // canImport(NIOSSL)