Skip to content

Commit

Permalink
Accept net.OpErrors in this test, too
Browse files Browse the repository at this point in the history
If a connection.close operation fails before the connection is marked
as closed internally, it's still a reasonable error for Connection#Close to return.

Note that it only happens with a certain degree of concurrency
in this test and thus the occurrence is quite unlikely in practice.

References #227.
  • Loading branch information
michaelklishin committed Dec 3, 2016
1 parent 75d0e3d commit 1571aa2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package amqp

import (
"log"
"net"
"sync"
"testing"
)
Expand Down Expand Up @@ -48,13 +49,22 @@ func TestConcurrentClose(t *testing.T) {
log.Fatalf("Could't connect to amqp server, err = %s", err)
}

n := 32
wg := sync.WaitGroup{}
wg.Add(5)
for i := 0; i < 5; i++ {
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
err := conn.Close()
if err != nil && err != ErrClosed {
log.Fatalf("Expected nil or ErrClosed - got %#v, type is %T", err, err)
switch err.(type) {
case *Error:
log.Fatalf("Expected no error, or ErrClosed, or a net.OpError from conn.Close(), got %#v (%#v) of type %T", err, err.Error(), err)
case *net.OpError:
// this is acceptable: we got a net.OpError
// before the connection was marked as closed
break;
}

}
wg.Done()
}()
Expand Down

0 comments on commit 1571aa2

Please sign in to comment.