Skip to content

Commit

Permalink
These ones were the ones testing Open scenarios. The issue is that Op… (
Browse files Browse the repository at this point in the history
#57)

* These ones were the ones testing Open scenarios. The issue is that Open and Close, rwc.Open and rwc.Close can at the same time write on:

c.allocator = newAllocator(1, c.Config.ChannelMax)
connection.go line 444 and
connection.go line 849

while shutdown is protected by the structure mutex m, OpenComplete() is not causing the race.

While it's not clear if the library should protect this eventuality, the tests are testing the Open function, so I think the close can be put in the main thread avoiding the race and not affecting the test validity

* adding t.Cleanup

Co-authored-by: Daniele Palaia <[email protected]>
  • Loading branch information
DanielePalaia and Daniele Palaia authored Mar 25, 2022
1 parent 34f6f31 commit 3d56e20
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ func (t *server) channelOpen(id int) {

func TestDefaultClientProperties(t *testing.T) {
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })

go func() {
srv.connectionOpen()
rwc.Close()

}()

if c, err := Open(rwc, defaultConfig()); err != nil {
Expand All @@ -236,10 +237,12 @@ func TestDefaultClientProperties(t *testing.T) {
if want, got := defaultLocale, srv.start.Locale; want != got {
t.Errorf("expected locale %s got: %s", want, got)
}

}

func TestCustomClientProperties(t *testing.T) {
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })

config := defaultConfig()
config.Properties = Table{
Expand All @@ -249,7 +252,7 @@ func TestCustomClientProperties(t *testing.T) {

go func() {
srv.connectionOpen()
rwc.Close()

}()

if c, err := Open(rwc, config); err != nil {
Expand All @@ -263,28 +266,31 @@ func TestCustomClientProperties(t *testing.T) {
if want, got := config.Properties["version"], srv.start.ClientProperties["version"]; want != got {
t.Errorf("expected version %s got: %s", want, got)
}

}

func TestOpen(t *testing.T) {
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })
go func() {
srv.connectionOpen()
rwc.Close()

}()

if c, err := Open(rwc, defaultConfig()); err != nil {
t.Fatalf("could not create connection: %v (%s)", c, err)
}

}

func TestChannelOpen(t *testing.T) {
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })

go func() {
srv.connectionOpen()
srv.channelOpen(1)

rwc.Close()
}()

c, err := Open(rwc, defaultConfig())
Expand All @@ -296,10 +302,12 @@ func TestChannelOpen(t *testing.T) {
if err != nil {
t.Fatalf("could not open channel: %v (%s)", ch, err)
}

}

func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) {
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })

go func() {
srv.expectAMQP()
Expand All @@ -310,11 +318,13 @@ func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) {
if err != ErrSASL {
t.Fatalf("expected ErrSASL got: %+v on %+v", err, c)
}

}

func TestOpenAMQPlainAuth(t *testing.T) {
auth := make(chan Table)
rwc, srv := newSession(t)
t.Cleanup(func() { rwc.Close() })

go func() {
srv.expectAMQP()
Expand All @@ -326,7 +336,7 @@ func TestOpenAMQPlainAuth(t *testing.T) {

srv.recv(0, &connectionOpen{})
srv.send(0, &connectionOpenOk{})
rwc.Close()

auth <- table
}()

Expand All @@ -340,6 +350,7 @@ func TestOpenAMQPlainAuth(t *testing.T) {
if table["PASSWORD"] != defaultPassword {
t.Fatalf("unexpected password: want: %s, got: %s", defaultPassword, table["PASSWORD"])
}

}

func TestOpenFailedCredentials(t *testing.T) {
Expand All @@ -356,6 +367,7 @@ func TestOpenFailedCredentials(t *testing.T) {
if err != ErrCredentials {
t.Fatalf("expected ErrCredentials got: %+v on %+v", err, c)
}

}

func TestOpenFailedVhost(t *testing.T) {
Expand Down

0 comments on commit 3d56e20

Please sign in to comment.