Skip to content

Commit

Permalink
Merge branch 'kalman-fix/concurrent-inq-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Nov 8, 2023
2 parents b349c31 + 2fdc741 commit 7c3d21e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 19 additions & 0 deletions ibmmq/ibmmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,22 @@ func TestNewMQDLHWithMQMD(t *testing.T) {
t.Fail()
}
}

func TestGetAttrInfoConcurrentCalls(t *testing.T) {
// NOTE: This test should be run with `go test -race`.
attrs := []int32{
MQCA_BACKOUT_REQ_Q_NAME,
MQIA_BACKOUT_THRESHOLD,
}
count := 1_000
doneCh := make(chan struct{}, count)
for i := 0; i < count; i++ {
go func() {
getAttrInfo(attrs)
doneCh <- struct{}{}
}()
}
for i := 0; i < count; i++ {
<-doneCh
}
}
8 changes: 4 additions & 4 deletions ibmmq/mqiattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import "C"
import (
"fmt"
"os"
"sync"
)

/*
Expand Down Expand Up @@ -130,7 +131,7 @@ var mqInqLength = map[int32]int32{
C.MQCA_XMIT_Q_NAME: C.MQ_Q_NAME_LENGTH,
}

var charAttrsAdded = false
var charAttrsAddedOnce sync.Once

/*
* Return how many char & int attributes are in the list of selectors, and the
Expand All @@ -141,7 +142,7 @@ func getAttrInfo(attrs []int32) (int, int, int) {
var charAttrCount = 0
var intAttrCount = 0

if !charAttrsAdded {
charAttrsAddedOnce.Do(func() {
maxNewAttrs := C.MAX_NEW_MQCA_ATTRS
attrVals := make([]C.MQLONG, maxNewAttrs)
attrLens := make([]C.MQLONG, maxNewAttrs)
Expand All @@ -155,8 +156,7 @@ func getAttrInfo(attrs []int32) (int, int, int) {
for i := 0; i < addedAttrs; i++ {
mqInqLength[int32(attrVals[i])] = int32(attrLens[i])
}
charAttrsAdded = true
}
})

for i := 0; i < len(attrs); i++ {
if v, ok := mqInqLength[attrs[i]]; ok {
Expand Down

0 comments on commit 7c3d21e

Please sign in to comment.