Skip to content

Commit

Permalink
Some unit tests in connection were showing a race condition (see rabb…
Browse files Browse the repository at this point in the history
…itmq#31):

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
  • Loading branch information
Daniele Palaia committed Mar 25, 2022
1 parent d25e3e5 commit 3b21050
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestDefaultClientProperties(t *testing.T) {

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

}()

if c, err := Open(rwc, defaultConfig()); err != nil {
Expand All @@ -229,13 +229,14 @@ func TestDefaultClientProperties(t *testing.T) {
t.Errorf("expected product %s got: %s", want, got)
}

if want, got := defaultVersion, srv.start.ClientProperties["version"]; want != got {
if want, got := buildVersion, srv.start.ClientProperties["version"]; want != got {
t.Errorf("expected version %s got: %s", want, got)
}

if want, got := defaultLocale, srv.start.Locale; want != got {
t.Errorf("expected locale %s got: %s", want, got)
}
rwc.Close()
}

func TestCustomClientProperties(t *testing.T) {
Expand All @@ -249,7 +250,7 @@ func TestCustomClientProperties(t *testing.T) {

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

}()

if c, err := Open(rwc, config); err != nil {
Expand All @@ -263,18 +264,21 @@ 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)
}

rwc.Close()
}

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

}()

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

func TestChannelOpen(t *testing.T) {
Expand Down Expand Up @@ -326,7 +330,7 @@ func TestOpenAMQPlainAuth(t *testing.T) {

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

auth <- table
}()

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

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

0 comments on commit 3b21050

Please sign in to comment.