Skip to content

Commit

Permalink
fixed: proper order of destruction of client_session's members
Browse files Browse the repository at this point in the history
  • Loading branch information
tyoma committed Aug 7, 2022
1 parent 01b7fb7 commit 0a3ad74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ipc/client_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ namespace micro_profiler

private:
template <typename RequestT, typename CallbackConstructorT>
void request_internal(int id, const RequestT &payload,
const CallbackConstructorT &callback_ctor);
void request_internal(int id, const RequestT &payload, const CallbackConstructorT &callback_ctor);

private:
pod_vector<byte> _buffer;
token_t _token;
channel_ptr_t _outbound_active;
channel *_outbound;
std::shared_ptr<callbacks_t> _callbacks;
std::shared_ptr<message_callbacks_t> _message_callbacks;
channel_ptr_t _outbound_active;
channel *_outbound;
};


Expand Down
40 changes: 40 additions & 0 deletions ipc/tests/ClientSessionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace micro_profiler
shared_ptr<mocks::channel> outbound;
shared_ptr<void> req[10];


test( SessionIsCreatedOnConstruction )
{
// INIT / ACT
Expand Down Expand Up @@ -556,6 +557,45 @@ namespace micro_profiler
send_message(s, 154);
}


class message_on_destruction : public channel
{
public:
message_on_destruction(ClientSessionTests &self, channel &inbound_)
: _self(self), _inbound(inbound_)
{ }

~message_on_destruction()
{
for (auto i = begin(_self.req); i != end(_self.req); ++i)
i->reset();
send_standard(_inbound, 19, 1);
send_message(_inbound, 13);
send_standard(_inbound, 19, 1);
}

virtual void disconnect() throw() override { }
virtual void message(const_byte_range /*payload*/) override { }

private:
ClientSessionTests &_self;
channel &_inbound;
};

test( MessagesGotAtChannelDestructionAreRouted )
{
// INIT
auto s = make_shared<client_session>([&] (channel &inbound) {
return make_shared<message_on_destruction>(*this, inbound);
});

s->subscribe(req[0], 13, [&] (deserializer &) { });
s->request(req[1], 100, 99, 19, [&] (deserializer &) { });

// ACT / ASSERT
s.reset();
}

end_test_suite
}
}
Expand Down

0 comments on commit 0a3ad74

Please sign in to comment.