Skip to content

Commit cdb2128

Browse files
committed
fix LookupServiceTest.testAfterClientShutdown
1 parent e5f9cca commit cdb2128

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

lib/Client.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,16 @@ DECLARE_LOG_OBJECT()
3434

3535
namespace pulsar {
3636

37-
Client::Client(const std::shared_ptr<ClientImpl>& impl) : impl_(impl) {}
37+
Client::Client(const std::shared_ptr<ClientImpl>& impl) : impl_(impl) { impl_->initialize(); }
3838

3939
Client::Client(const std::string& serviceUrl) : Client(serviceUrl, ClientConfiguration()) {}
4040

4141
Client::Client(const std::string& serviceUrl, const ClientConfiguration& clientConfiguration)
42-
: impl_(std::make_shared<ClientImpl>(serviceUrl, clientConfiguration)) {
43-
impl_->initialize();
44-
}
42+
: Client(std::make_shared<ClientImpl>(serviceUrl, clientConfiguration)) {}
4543

4644
Client Client::create(std::unique_ptr<ServiceInfoProvider> serviceInfoProvider,
4745
const ClientConfiguration& clientConfiguration) {
48-
Client client(std::make_shared<ClientImpl>(std::move(serviceInfoProvider), clientConfiguration));
49-
client.impl_->initialize();
50-
return client;
46+
return Client(std::make_shared<ClientImpl>(std::move(serviceInfoProvider), clientConfiguration));
5147
}
5248

5349
Result Client::createProducer(const std::string& topic, Producer& producer) {

tests/LookupServiceTest.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,23 +527,24 @@ class MockLookupService : public BinaryProtoLookupService {
527527
};
528528

529529
TEST(LookupServiceTest, testAfterClientShutdown) {
530-
auto client = std::make_shared<ClientImpl>(
530+
auto client = PulsarFriend::newClientFromImpl(std::make_shared<ClientImpl>(
531531
"pulsar://localhost:6650", ClientConfiguration{},
532532
[](const ServiceInfo& serviceInfo, const ClientConfiguration&, ConnectionPool& pool) {
533533
return std::make_shared<MockLookupService>(serviceInfo, pool, ClientConfiguration{});
534-
});
534+
}));
535+
535536
std::promise<Result> promise;
536-
client->subscribeAsync("lookup-service-test-after-client-shutdown", "sub", ConsumerConfiguration{},
537-
[&promise](Result result, const Consumer&) { promise.set_value(result); });
537+
client.subscribeAsync("lookup-service-test-after-client-shutdown", "sub", ConsumerConfiguration{},
538+
[&promise](Result result, const Consumer&) { promise.set_value(result); });
538539
// When shutdown is called, there is a pending lookup request due to the 1st lookup is failed in
539540
// MockLookupService. Verify shutdown will cancel it and return ResultDisconnected.
540-
client->shutdown();
541+
client.shutdown();
541542
EXPECT_EQ(ResultDisconnected, promise.get_future().get());
542543

543544
// A new subscribeAsync call will fail immediately in the current thread
544545
Result result = ResultOk;
545-
client->subscribeAsync("lookup-service-test-retry-after-destroyed", "sub", ConsumerConfiguration{},
546-
[&result](Result innerResult, const Consumer&) { result = innerResult; });
546+
client.subscribeAsync("lookup-service-test-retry-after-destroyed", "sub", ConsumerConfiguration{},
547+
[&result](Result innerResult, const Consumer&) { result = innerResult; });
547548
EXPECT_EQ(ResultAlreadyClosed, result);
548549
}
549550

tests/PulsarFriend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class PulsarFriend {
124124

125125
static std::shared_ptr<ClientImpl> getClientImplPtr(Client client) { return client.impl_; }
126126

127+
static Client newClientFromImpl(const ClientImplPtr& impl) { return Client{impl}; }
128+
127129
static auto getProducers(const Client& client) -> decltype(ClientImpl::producers_)& {
128130
return getClientImplPtr(client)->producers_;
129131
}

0 commit comments

Comments
 (0)