Skip to content

Commit 3d56e20

Browse files
DanielePalaiaDaniele Palaia
andauthored
These ones were the ones testing Open scenarios. The issue is that Op… (#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 <dpalaia@dpalaia-a02.vmware.com>
1 parent 34f6f31 commit 3d56e20

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

client_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ func (t *server) channelOpen(id int) {
215215

216216
func TestDefaultClientProperties(t *testing.T) {
217217
rwc, srv := newSession(t)
218+
t.Cleanup(func() { rwc.Close() })
218219

219220
go func() {
220221
srv.connectionOpen()
221-
rwc.Close()
222+
222223
}()
223224

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

241243
func TestCustomClientProperties(t *testing.T) {
242244
rwc, srv := newSession(t)
245+
t.Cleanup(func() { rwc.Close() })
243246

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

250253
go func() {
251254
srv.connectionOpen()
252-
rwc.Close()
255+
253256
}()
254257

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

268272
func TestOpen(t *testing.T) {
269273
rwc, srv := newSession(t)
274+
t.Cleanup(func() { rwc.Close() })
270275
go func() {
271276
srv.connectionOpen()
272-
rwc.Close()
277+
273278
}()
274279

275280
if c, err := Open(rwc, defaultConfig()); err != nil {
276281
t.Fatalf("could not create connection: %v (%s)", c, err)
277282
}
283+
278284
}
279285

280286
func TestChannelOpen(t *testing.T) {
281287
rwc, srv := newSession(t)
288+
t.Cleanup(func() { rwc.Close() })
282289

283290
go func() {
284291
srv.connectionOpen()
285292
srv.channelOpen(1)
286293

287-
rwc.Close()
288294
}()
289295

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

301308
func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) {
302309
rwc, srv := newSession(t)
310+
t.Cleanup(func() { rwc.Close() })
303311

304312
go func() {
305313
srv.expectAMQP()
@@ -310,11 +318,13 @@ func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) {
310318
if err != ErrSASL {
311319
t.Fatalf("expected ErrSASL got: %+v on %+v", err, c)
312320
}
321+
313322
}
314323

315324
func TestOpenAMQPlainAuth(t *testing.T) {
316325
auth := make(chan Table)
317326
rwc, srv := newSession(t)
327+
t.Cleanup(func() { rwc.Close() })
318328

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

327337
srv.recv(0, &connectionOpen{})
328338
srv.send(0, &connectionOpenOk{})
329-
rwc.Close()
339+
330340
auth <- table
331341
}()
332342

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

345356
func TestOpenFailedCredentials(t *testing.T) {
@@ -356,6 +367,7 @@ func TestOpenFailedCredentials(t *testing.T) {
356367
if err != ErrCredentials {
357368
t.Fatalf("expected ErrCredentials got: %+v on %+v", err, c)
358369
}
370+
359371
}
360372

361373
func TestOpenFailedVhost(t *testing.T) {

0 commit comments

Comments
 (0)