Skip to content

Commit f903316

Browse files
committed
Avoid exit() in channelStateChange; abort test cleanly if connection fails
1 parent 7ca5f9d commit f903316

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

test/src/testChannelMonitor.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class ChannelRequesterImpl : public ChannelRequester
138138
{
139139
private:
140140
Event event;
141+
bool connected = false;
141142

142143
public:
143144

@@ -167,18 +168,18 @@ class ChannelRequesterImpl : public ChannelRequester
167168
virtual void channelStateChange(const Channel::shared_pointer& /*channel*/, Channel::ConnectionState connectionState)
168169
{
169170
if (connectionState == Channel::CONNECTED) {
170-
event.signal();
171-
}
172-
else {
171+
connected = true;
172+
} else {
173173
cout << Channel::ConnectionStateNames[connectionState] << endl;
174-
testFail("Channel did not reach CONNECTED state");
175-
event.signal(); // To ensure the test does not hang
174+
connected = false;
176175
}
176+
event.signal();
177177
}
178178

179179
bool waitUntilConnected(double timeOut)
180180
{
181-
return event.wait(timeOut);
181+
event.wait(timeOut);
182+
return connected;
182183
}
183184
};
184185

@@ -210,6 +211,9 @@ static void test()
210211
Channel::shared_pointer channel = provider->createChannel(recordName, channelRequesterImpl);
211212
bool channelConnected = channelRequesterImpl->waitUntilConnected(1.0);
212213
testOk1(channelConnected);
214+
if (!channelConnected) {
215+
testAbort("Channel did not reach CONNECTED state");
216+
}
213217
if (channelConnected) {
214218
string remoteAddress = channel->getRemoteAddress();
215219
cout << "remote address: " << remoteAddress << endl;

0 commit comments

Comments
 (0)