PROTON-1305: Go sporadic test failure in electron_test

Reliably reproduced by:
    . config.sh && go test qpid.apache.org/electron -run TestLinkCloseInterrupt 
-count 100

Fixed missing error check in receiver.ReceiveTimeout()


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b4d0912b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b4d0912b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b4d0912b

Branch: refs/heads/master
Commit: b4d0912b0d8fa7c2ff2115635dece381f5d48868
Parents: 158ad91
Author: Alan Conway <acon...@redhat.com>
Authored: Thu Sep 8 19:37:25 2016 -0400
Committer: Alan Conway <acon...@redhat.com>
Committed: Tue Sep 20 17:39:15 2016 -0400

----------------------------------------------------------------------
 .../qpid.apache.org/electron/messaging_test.go  |  9 +++---
 .../go/src/qpid.apache.org/electron/receiver.go | 29 +++++++++++---------
 2 files changed, 21 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b4d0912b/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
----------------------------------------------------------------------
diff --git 
a/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go 
b/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
index 4a9e652..c5c351a 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
@@ -324,22 +324,23 @@ func (p *pairs) receiverSender() (Receiver, Sender) {
 type result struct {
        label string
        err   error
+       value interface{}
 }
 
 func (r result) String() string { return fmt.Sprintf("%v(%v)", r.err, r.label) 
}
 
 func doSend(snd Sender, results chan result) {
        err := snd.SendSync(amqp.NewMessage()).Error
-       results <- result{"send", err}
+       results <- result{"send", err, nil}
 }
 
 func doReceive(rcv Receiver, results chan result) {
-       _, err := rcv.Receive()
-       results <- result{"receive", err}
+       msg, err := rcv.Receive()
+       results <- result{"receive", err, msg}
 }
 
 func doDisposition(ack <-chan Outcome, results chan result) {
-       results <- result{"disposition", (<-ack).Error}
+       results <- result{"disposition", (<-ack).Error, nil}
 }
 
 // Senders get credit immediately if receivers have prefetch set

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b4d0912b/proton-c/bindings/go/src/qpid.apache.org/electron/receiver.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/electron/receiver.go 
b/proton-c/bindings/go/src/qpid.apache.org/electron/receiver.go
index 026a385..606e4d6 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/electron/receiver.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/electron/receiver.go
@@ -125,28 +125,31 @@ func (r *receiver) Receive() (rm ReceivedMessage, err 
error) {
        return r.ReceiveTimeout(Forever)
 }
 
-func (r *receiver) ReceiveTimeout(timeout time.Duration) (ReceivedMessage, 
error) {
+func (r *receiver) ReceiveTimeout(timeout time.Duration) (rm ReceivedMessage, 
err error) {
        assert(r.buffer != nil, "Receiver is not open: %s", r)
-       select { // Check for immediate availability, avoid caller() inject.
-       case rm := <-r.buffer:
-               r.flowTopUp()
-               return rm, nil
-       default:
-       }
        if !r.prefetch { // Per-caller flow control
-               r.caller(+1)
-               defer r.caller(-1)
+               select { // Check for immediate availability, avoid caller() 
inject
+               case rm2, ok := <-r.buffer:
+                       if ok {
+                               rm = rm2
+                       } else {
+                               err = r.Error()
+                       }
+                       return
+               default: // Not immediately available, inject caller() counts
+                       r.caller(+1)
+                       defer r.caller(-1)
+               }
        }
        rmi, err := timedReceive(r.buffer, timeout)
        switch err {
        case nil:
                r.flowTopUp()
-               return rmi.(ReceivedMessage), err
+               rm = rmi.(ReceivedMessage)
        case Closed:
-               return ReceivedMessage{}, r.Error()
-       default:
-               return ReceivedMessage{}, err
+               err = r.Error()
        }
+       return
 }
 
 // Called in proton goroutine on MMessage event.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to