You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/03/14 14:42:12 UTC

[thrift] branch master updated: THRIFT-5121: Fix inverted logic when testing message type Client: Swift Patch: Alexander Edge

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new b013dc0  THRIFT-5121: Fix inverted logic when testing message type Client: Swift Patch: Alexander Edge
b013dc0 is described below

commit b013dc004a019c9a30689b8e49ade34c3b18b7e5
Author: Alexander Edge <al...@alexedge.co.uk>
AuthorDate: Thu Feb 27 11:25:55 2020 +0000

    THRIFT-5121: Fix inverted logic when testing message type
    Client: Swift
    Patch: Alexander Edge
    
    This closes #2036
---
 lib/swift/Sources/TMultiplexedProcessor.swift      |  2 +-
 .../ThriftTests/TMultiplexedProcessorTests.swift   | 38 ++++++++++++++++------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/lib/swift/Sources/TMultiplexedProcessor.swift b/lib/swift/Sources/TMultiplexedProcessor.swift
index 661d4a7..7f40808 100644
--- a/lib/swift/Sources/TMultiplexedProcessor.swift
+++ b/lib/swift/Sources/TMultiplexedProcessor.swift
@@ -58,7 +58,7 @@ public class MultiplexedProcessor: TProcessor {
 
   public func process(on inProtocol: TProtocol, outProtocol: TProtocol) throws {
     let message = try inProtocol.readMessageBegin()
-    guard message.1 != .call && message.1 != .oneway else { throw Error.incompatibleMessageType(message.1) }
+    guard message.1 == .call || message.1 == .oneway else { throw Error.incompatibleMessageType(message.1) }
     if let separatorIndex = message.0.firstIndex(of: Character(.multiplexSeparator)) {
       let serviceName = String(message.0.prefix(upTo: separatorIndex))
       let messageName = String(message.0.suffix(from: message.0.index(after: separatorIndex)))
diff --git a/lib/swift/Tests/ThriftTests/TMultiplexedProcessorTests.swift b/lib/swift/Tests/ThriftTests/TMultiplexedProcessorTests.swift
index 190ff13..559ff0b 100644
--- a/lib/swift/Tests/ThriftTests/TMultiplexedProcessorTests.swift
+++ b/lib/swift/Tests/ThriftTests/TMultiplexedProcessorTests.swift
@@ -54,32 +54,32 @@ class TMultiplexedProcessorTests: XCTestCase {
     transport.reset()
   }
 
-  func testCallMessageThrowsError() throws {
-    try proto.writeMessageBegin(name: "message", type: .call, sequenceID: 1)
+  func testExceptionMessageThrowsError() throws {
+    try proto.writeMessageBegin(name: "message", type: .exception, sequenceID: 1)
     try transport.flush()
     XCTAssertThrowsError(try sut.process(on: proto, outProtocol: proto)) { error in
       guard case MultiplexedProcessor.Error.incompatibleMessageType(let type) = error else {
         XCTFail()
         return
       }
-      XCTAssertEqual(type, .call)
+      XCTAssertEqual(type, .exception)
     }
   }
 
-  func testOneWayMessageThrowsError() throws {
-    try proto.writeMessageBegin(name: "message", type: .oneway, sequenceID: 1)
+  func testReplyMessageThrowsError() throws {
+    try proto.writeMessageBegin(name: "message", type: .reply, sequenceID: 1)
     try transport.flush()
     XCTAssertThrowsError(try sut.process(on: proto, outProtocol: proto)) { error in
       guard case MultiplexedProcessor.Error.incompatibleMessageType(let type) = error else {
         XCTFail()
         return
       }
-      XCTAssertEqual(type, .oneway)
+      XCTAssertEqual(type, .reply)
     }
   }
 
   func testMissingDefaultProcessorThrowsError() throws {
-    try proto.writeMessageBegin(name: "message", type: .reply, sequenceID: 1)
+    try proto.writeMessageBegin(name: "message", type: .call, sequenceID: 1)
     try transport.flush()
     XCTAssertThrowsError(try sut.process(on: proto, outProtocol: proto)) { error in
       guard case MultiplexedProcessor.Error.missingDefaultProcessor = error else {
@@ -93,7 +93,7 @@ class TMultiplexedProcessorTests: XCTestCase {
     let calculator = Calculator()
     let calculatorProcessor = CalculatorProcessor(service: calculator)
     sut.register(defaultProcessor: calculatorProcessor)
-    try proto.writeMessageBegin(name: "message", type: .reply, sequenceID: 1)
+    try proto.writeMessageBegin(name: "message", type: .call, sequenceID: 1)
     try transport.flush()
     try sut.process(on: proto, outProtocol: proto)
     XCTAssertTrue(calculatorProcessor.processCalled)
@@ -103,14 +103,14 @@ class TMultiplexedProcessorTests: XCTestCase {
     let calculator = Calculator()
     let calculatorProcessor = CalculatorProcessor(service: calculator)
     sut.register(processor: calculatorProcessor, for: "Calculator")
-    try proto.writeMessageBegin(name: "Calculator:message", type: .reply, sequenceID: 1)
+    try proto.writeMessageBegin(name: "Calculator:message", type: .call, sequenceID: 1)
     try transport.flush()
     try sut.process(on: proto, outProtocol: proto)
     XCTAssertTrue(calculatorProcessor.processCalled)
   }
 
   func testMissingProcessorForMultiplexedMessageThrowsError() throws {
-    try proto.writeMessageBegin(name: "Calculator:message", type: .reply, sequenceID: 1)
+    try proto.writeMessageBegin(name: "Calculator:message", type: .call, sequenceID: 1)
     try transport.flush()
     XCTAssertThrowsError(try sut.process(on: proto, outProtocol: proto)) { error in
       guard case MultiplexedProcessor.Error.missingProcessor(let serviceName) = error else {
@@ -120,4 +120,22 @@ class TMultiplexedProcessorTests: XCTestCase {
       XCTAssertEqual(serviceName, "Calculator")
     }
   }
+
+  func testCallMessageDoesNotThrowError() throws {
+    let calculator = Calculator()
+    let calculatorProcessor = CalculatorProcessor(service: calculator)
+    sut.register(defaultProcessor: calculatorProcessor)
+    try proto.writeMessageBegin(name: "message", type: .call, sequenceID: 1)
+    try transport.flush()
+    try sut.process(on: proto, outProtocol: proto)
+  }
+
+  func testOneWayMessageDoesNotThrowError() throws {
+    let calculator = Calculator()
+    let calculatorProcessor = CalculatorProcessor(service: calculator)
+    sut.register(defaultProcessor: calculatorProcessor)
+    try proto.writeMessageBegin(name: "message", type: .oneway, sequenceID: 1)
+    try transport.flush()
+    try sut.process(on: proto, outProtocol: proto)
+  }
 }