Skip to content

Commit

Permalink
Make bgp_peer_test more stable
Browse files Browse the repository at this point in the history
This test used to fail occasionally when the StateMachine tried to
delete the mock TcpSession which would have an invalid refcount 0.

Fix by using a mock StateMachine which overrides the DeleteSession
method.

Change-Id: Ibf2654477b4f6d995d8be757ac636dee4a4901b1
Partial-Bug: 1602347
  • Loading branch information
Nischal Sheth committed Oct 23, 2016
1 parent a51117a commit 905eeee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bgp/state_machine.h
Expand Up @@ -94,7 +94,7 @@ class StateMachine : public sc::state_machine<StateMachine, fsm::Idle> {
};

explicit StateMachine(BgpPeer *peer);
~StateMachine();
virtual ~StateMachine();

void Initialize();
void Shutdown(int subcode);
Expand Down Expand Up @@ -125,7 +125,7 @@ class StateMachine : public sc::state_machine<StateMachine, fsm::Idle> {
bool IdleHoldTimerRunning();

void StartSession();
void DeleteSession(BgpSession *session);
virtual void DeleteSession(BgpSession *session);
void AssignSession(bool active);

virtual void OnSessionEvent(TcpSession *session, TcpSession::Event event);
Expand Down
9 changes: 9 additions & 0 deletions src/bgp/test/bgp_peer_test.cc
Expand Up @@ -7,6 +7,7 @@
#include "base/task_annotations.h"
#include "base/test/task_test_util.h"
#include "bgp/bgp_config.h"
#include "bgp/bgp_factory.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_peer.h"
#include "bgp/bgp_session.h"
Expand All @@ -15,6 +16,12 @@
// Use this test to mock BgpPeer and test selected functionality in BgpPeer as
// desired. e.g. EndOfRibSendTimerExpired() API.

class StateMachineMock : public StateMachine {
public:
explicit StateMachineMock(BgpPeer *peer) : StateMachine(peer) { }
virtual void DeleteSession(BgpSession *session) { }
};

class BgpSessionMock : public BgpSession {
public:
BgpSessionMock(BgpSessionManager *manager)
Expand Down Expand Up @@ -415,6 +422,8 @@ INSTANTIATE_TEST_CASE_P(BgpPeerTestWithParams, BgpPeerParamTest,
static void SetUp() {
bgp_log_test::init();
ControlNode::SetDefaultSchedulingPolicy();
BgpObjectFactory::Register<StateMachine>(
boost::factory<StateMachineMock *>());
}

static void TearDown() {
Expand Down

0 comments on commit 905eeee

Please sign in to comment.