-
Notifications
You must be signed in to change notification settings - Fork 19
/
memoryleaks_test.go
167 lines (133 loc) · 4.43 KB
/
memoryleaks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (c) IBM Corporation 2023
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package main
import (
"fmt"
"runtime"
"testing"
"time"
"github.com/ibm-messaging/mq-golang-jms20/jms20subset"
"github.com/ibm-messaging/mq-golang-jms20/mqjms"
"github.com/stretchr/testify/assert"
)
/*
* Test for memory leak when there is no message to be received.
*
* This test is not included in the normal bucket as it sends an enormous number of
* messages, and requires human observation of the total process size to establish whether
* it passes or not, so can only be run under human supervision
*/
func DONT_RUNTestLeakOnEmptyGet(t *testing.T) {
// Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
//cf, cfErr := mqjms.CreateConnectionFactoryFromDefaultJSONFiles()
//assert.Nil(t, cfErr)
// Initialise the attributes of the CF in whatever way you like
cf := mqjms.ConnectionFactoryImpl{
QMName: "QM1",
Hostname: "localhost",
PortNumber: 1414,
ChannelName: "DEV.APP.SVRCONN",
UserName: "app",
Password: "passw0rd",
}
// Creates a connection to the queue manager, using defer to close it automatically
// at the end of the function (if it was created successfully)
context, ctxErr := cf.CreateContext()
assert.Nil(t, ctxErr)
if context != nil {
defer context.Close()
}
// Now send the message and get it back again, to check that it roundtripped.
queue := context.CreateQueue("DEV.QUEUE.1")
consumer, errCons := context.CreateConsumer(queue)
if consumer != nil {
defer consumer.Close()
}
assert.Nil(t, errCons)
for i := 1; i < 35000; i++ {
rcvMsg, errRvc := consumer.ReceiveNoWait()
assert.Nil(t, errRvc)
assert.Nil(t, rcvMsg)
if i%1000 == 0 {
fmt.Println("Messages:", i)
}
}
fmt.Println("Finished receive calls - waiting for cooldown.")
runtime.GC()
time.Sleep(30 * time.Second)
}
/*
* Test for memory leak when sending and receiving messages
*
* This test is not included in the normal bucket as it sends an enormous number of
* messages, and requires human observation of the total process size to establish whether
* it passes or not, so can only be run under human supervision
*/
func DONTRUN_TestLeakOnPutGet(t *testing.T) {
// Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
//cf, cfErr := mqjms.CreateConnectionFactoryFromDefaultJSONFiles()
//assert.Nil(t, cfErr)
// Initialise the attributes of the CF in whatever way you like
cf := mqjms.ConnectionFactoryImpl{
QMName: "QM1",
Hostname: "localhost",
PortNumber: 1414,
ChannelName: "DEV.APP.SVRCONN",
UserName: "app",
Password: "passw0rd",
}
// Creates a connection to the queue manager, using defer to close it automatically
// at the end of the function (if it was created successfully)
context, ctxErr := cf.CreateContext()
assert.Nil(t, ctxErr)
if context != nil {
defer context.Close()
}
// Now send the message and get it back again, to check that it roundtripped.
queue := context.CreateQueue("DEV.QUEUE.1")
consumer, errCons := context.CreateConsumer(queue)
if consumer != nil {
defer consumer.Close()
}
assert.Nil(t, errCons)
ttlMillis := 20000
producer := context.CreateProducer().SetTimeToLive(ttlMillis)
for i := 1; i < 25000; i++ {
// Create a TextMessage and check that we can populate it
msgBody := "Message " + fmt.Sprint(i)
txtMsg := context.CreateTextMessage()
txtMsg.SetText(msgBody)
txtMsg.SetIntProperty("MessageNumber", i)
errSend := producer.Send(queue, txtMsg)
assert.Nil(t, errSend)
rcvMsg, errRvc := consumer.ReceiveNoWait()
assert.Nil(t, errRvc)
assert.NotNil(t, rcvMsg)
// Check message body.
switch msg := rcvMsg.(type) {
case jms20subset.TextMessage:
assert.Equal(t, msgBody, *msg.GetText())
default:
assert.Fail(t, "Got something other than a text message")
}
// Check messageID
assert.Equal(t, txtMsg.GetJMSMessageID(), rcvMsg.GetJMSMessageID())
// Check int property
rcvMsgNum, propErr := rcvMsg.GetIntProperty("MessageNumber")
assert.Nil(t, propErr)
assert.Equal(t, i, rcvMsgNum)
if i%1000 == 0 {
fmt.Println("Messages:", i)
}
}
fmt.Println("Finished receive calls - waiting for cooldown.")
runtime.GC()
time.Sleep(30 * time.Second)
}