Test for exception throws when channel name exist
Reviewers: zuza Reviewed By: zuza Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D641
This commit is contained in:
parent
7fe799f232
commit
82f1cb333d
@ -34,6 +34,10 @@ std::pair<EventStream*, std::shared_ptr<Channel>> Reactor::Open(const std::strin
|
||||
// TODO: Improve the check that the channel name does not exist in the
|
||||
// system.
|
||||
assert(connectors_.count(connector_name) == 0);
|
||||
if (connectors_.count(connector_name) != 0) {
|
||||
throw std::runtime_error("Connector with name " + connector_name
|
||||
+ "already exists");
|
||||
}
|
||||
auto it = connectors_.emplace(connector_name,
|
||||
std::make_shared<Connector>(Connector::Params{system_, name_, connector_name, mutex_, cvar_})).first;
|
||||
it->second->self_ptr_ = it->second;
|
||||
|
@ -10,9 +10,26 @@
|
||||
|
||||
#include "communication.hpp"
|
||||
|
||||
TEST(ChannelCreationTest, ThrowOnReusingChannelName) {
|
||||
struct Master : public Reactor {
|
||||
Master(System *system, std::string name) : Reactor(system, name) {}
|
||||
virtual void Run() {
|
||||
Open("channel");
|
||||
ASSERT_THROW(Open("channel"), std::runtime_error);
|
||||
CloseConnector("main");
|
||||
CloseConnector("channel");
|
||||
}
|
||||
};
|
||||
|
||||
System system;
|
||||
system.Spawn<Master>("master");
|
||||
system.AwaitShutdown();
|
||||
}
|
||||
|
||||
|
||||
TEST(ConnectorSetUpTest, CheckMainChannelIsSet) {
|
||||
struct Master : public Reactor {
|
||||
Master(System *system, std::string name) : Reactor(system, name) {}
|
||||
Master(System *system, std::string name) : Reactor(system, name) {}
|
||||
virtual void Run() {
|
||||
std::shared_ptr<Channel> channel;
|
||||
while (!(channel = system_->FindChannel("worker", "main")))
|
||||
|
Loading…
Reference in New Issue
Block a user