Skip to content

Commit 8111c21

Browse files
author
Steve Powell
committed
Adjusted test to limit hang if test fails.
1 parent cb13485 commit 8111c21

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/src/com/rabbitmq/client/test/AMQConnectionTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ public void testConnectionSendsSingleHeaderAndTimesOut() {
125125
* Test that we catch timeout between connect and negotiation of the connection being finished.
126126
*/
127127
public void testConnectionHangInNegotiation() {
128+
this._mockFrameHandler.setTimeoutCount(10); // to limit hang
128129
MyExceptionHandler handler = new MyExceptionHandler();
129-
assertEquals(0, _mockFrameHandler.countHeadersSent());
130+
assertEquals(0, this._mockFrameHandler.countHeadersSent());
130131
try {
131132
new AMQConnection(factory.getUsername(),
132133
factory.getPassword(),
133-
_mockFrameHandler,
134+
this._mockFrameHandler,
134135
Executors.newFixedThreadPool(1),
135136
factory.getVirtualHost(),
136137
factory.getClientProperties(),
@@ -143,7 +144,7 @@ public void testConnectionHangInNegotiation() {
143144
} catch(IOException signal) {
144145
// As expected
145146
}
146-
assertEquals(1, _mockFrameHandler.countHeadersSent());
147+
assertEquals(1, this._mockFrameHandler.countHeadersSent());
147148
// _connection.close(0, CLOSE_MESSAGE);
148149
List<Throwable> exceptionList = handler.getHandledExceptions();
149150
assertEquals("Only one exception expected", 1, exceptionList.size());
@@ -160,6 +161,8 @@ private static class MockFrameHandler implements FrameHandler {
160161
/** An optional exception for us to throw on reading frames */
161162
private IOException _exceptionOnReadingFrames;
162163

164+
private int timeoutCount = 0;
165+
163166
/** count how many headers we've sent
164167
* @return the number of sent headers
165168
*/
@@ -171,10 +174,18 @@ public void setExceptionOnReadingFrames(IOException exception) {
171174
_exceptionOnReadingFrames = exception;
172175
}
173176

177+
public void setTimeoutCount(int timeoutCount) {
178+
this.timeoutCount = timeoutCount;
179+
}
180+
174181
public Frame readFrame() throws IOException {
175182
if (_exceptionOnReadingFrames != null) {
176183
throw _exceptionOnReadingFrames;
177184
}
185+
if (this.timeoutCount > 0) {
186+
if (--this.timeoutCount == 0)
187+
throw new IOException("Mock Framehandler: too many timeouts.");
188+
}
178189
return null; // simulate a socket timeout
179190
}
180191

@@ -207,7 +218,7 @@ public int getPort() {
207218
}
208219
}
209220

210-
/** Mock frame handler to facilitate testing. */
221+
/** Exception handler to facilitate testing. */
211222
private class MyExceptionHandler implements ExceptionHandler {
212223
private List<Throwable> _handledExceptions = new ArrayList<Throwable>();
213224

0 commit comments

Comments
 (0)