Skip to content

Commit

Permalink
Revert test to demonstrate actual bug
Browse files Browse the repository at this point in the history
Follow-up to #85

When this test fails, RabbitMQ logs the following connection exception:

```
2022-05-24 11:00:12.747989+00:00 [error] <0.19502.2> Channel error on connection <0.19347.2> (172.17.0.1:46318 -> 172.17.0.2:5672, vhost: '/', user: 'guest'), channel 20:
2022-05-24 11:00:12.747989+00:00 [error] <0.19502.2> operation basic.publish caused a channel exception not_found: no exchange 'not-existing-exchange' in vhost '/'
2022-05-24 11:00:12.748614+00:00 [error] <0.19347.2> Error on AMQP connection <0.19347.2> (172.17.0.1:46318 -> 172.17.0.2:5672, vhost: '/', user: 'guest', state: running), channel 20:
2022-05-24 11:00:12.748614+00:00 [error] <0.19347.2>  operation basic.publish caused a connection exception channel_error: "expected 'channel.open'"
```
  • Loading branch information
lukebakken committed May 25, 2022
1 parent 3475ed2 commit 41da9d7
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,46 +1539,43 @@ func TestDeadlockConsumerIssue48(t *testing.T) {

// https://github.com/streadway/amqp/issues/46
func TestRepeatedChannelExceptionWithPublishAndMaxProcsIssue46(t *testing.T) {
var conn *Connection = nil
conn := integrationConnection(t, "issue46")
if conn == nil {
t.Fatal("conn is nil")
}

t.Cleanup(func() {
if conn != nil {
conn.Close()
}
conn.Close()
})

for i := 0; i < 100; i++ {
if conn == nil || conn.IsClosed() {
conn = integrationConnection(t, "issue46")
if conn == nil {
t.Fatal("conn is nil")
}
if conn == nil {
t.Fatal("conn is nil")
}

ch, err := conn.Channel()
if err, ok := err.(Error); ok {
if err.Code != 504 {
t.Fatalf("expected channel only exception i: %d got: %+v", i, err)
}
if conn.IsClosed() {
t.Fatal("conn is closed")
}

if ch == nil {
continue
ch, channelOpenError := conn.Channel()
if channelOpenError != nil {
t.Fatalf("error opening channel: %d error: %+v", i, channelOpenError)
}

for j := 0; j < 10; j++ {
if ch.IsClosed() {
break
} else {
err = ch.Publish("not-existing-exchange", "some-key", false, false, Publishing{Body: []byte("some-data")})
if err, ok := err.(Error); ok {
if err.Code != 504 {
t.Fatalf("expected channel only exception i: %d j: %d got: %+v", i, j, err)
}
if cerr := ch.Close(); cerr != nil {
t.Logf("error on channel close i: %d j: %d got: %+v", i, j, cerr)
}
break
if j == 0 {
t.Fatal("channel should not be closed")
}
// TODO remove this debug log
t.Logf("channel is closed, i: %d j: %d", i, j)
}
publishError := ch.Publish("not-existing-exchange", "some-key", false, false, Publishing{Body: []byte("some-data")})
if publishError, ok := publishError.(Error); ok {
if publishError.Code == 504 {
t.Logf("i: %d j: %d error: %+v", i, j, publishError)
} else {
t.Fatalf("expected channel only exception i: %d j: %d error: %+v", i, j, publishError)
}
}
}
Expand Down

0 comments on commit 41da9d7

Please sign in to comment.