@@ -539,6 +539,44 @@ final class IORingTests: XCTestCase {
539539 let unexpected = completion. result
540540 XCTFail ( " Unexpected poll event: 0x \( String ( unexpected, radix: 16 ) ) " )
541541 }
542+
543+ func testPollError( ) throws {
544+ try XCTSkipIf ( !uringEnabled, failureMessage)
545+ var ring = try IORing ( queueDepth: 8 )
546+ let ( readFD, writeFD) = try FileDescriptor . pipe ( options: . nonBlocking)
547+ defer {
548+ try ? readFD. close ( )
549+ try ? writeFD. close ( )
550+ }
551+
552+ try XCTSkipIf (
553+ !ring. supportedFeatures. contains ( . extendedArguments) ,
554+ " Kernel < 5.11: timeouts in io_uring_enter aren't supported. "
555+ )
556+
557+ let chunk = [ UInt8] ( repeating: 0 , count: 4096 )
558+ chunk. withUnsafeBytes {
559+ // Fill the pipe by writing until an operation fails
560+ while let written = try ? writeFD. write ( $0) , written > 0 { }
561+ }
562+
563+ let request = IORing . Request. pollAdd (
564+ writeFD, pollEvents: . pollOut, isMultiShot: false , context: 98
565+ )
566+ let success = try ring. submit ( linkedRequests: request)
567+ XCTAssertEqual ( success, true )
568+ try readFD. close ( )
569+
570+ let dt = Duration . seconds ( 1 )
571+ let completion = try ring. blockingConsumeCompletion ( timeout: dt)
572+ XCTAssertEqual ( completion. context, 98 )
573+
574+ let pollErr = IORing . Request. PollEvents. pollErr. rawValue
575+ let result = completion. result & Int32 ( pollErr)
576+ if result != pollErr {
577+ XCTFail ( " expected POLLERR, got 0x \( String ( result, radix: 16 ) ) " )
578+ }
579+ }
542580}
543581#endif // os(Linux)
544582#endif // compiler(>=6.2) && $Lifetimes
0 commit comments