Skip to content

Commit

Permalink
Add test for for Dsf update failing
Browse files Browse the repository at this point in the history
Summary: As titled

Reviewed By: zechengh09

Differential Revision:
D62064161

Privacy Context Container: L1125642

fbshipit-source-id: 5eb31e0784d2b9f02559973f04ac73fac8d195d8
  • Loading branch information
Jasmeet Bagga authored and facebook-github-bot committed Sep 2, 2024
1 parent 87ff339 commit b780b2e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fboss/agent/DsfSubscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class DsfSubscription {
template <typename T>
FRIEND_TEST(DsfSubscriptionTest, updateWithRollbackProtection);
template <typename T>
FRIEND_TEST(DsfSubscriptionTest, updateFailed);
template <typename T>
FRIEND_TEST(DsfSubscriptionTest, setupNeighbors);
};

Expand Down
41 changes: 41 additions & 0 deletions fboss/agent/test/DsfSubscriptionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "fboss/agent/AgentFsdbSyncManager.h"
#include "fboss/agent/DsfSubscription.h"
#include "fboss/agent/SwitchStats.h"
#include "fboss/agent/hw/mock/MockPlatform.h"
#include "fboss/agent/test/CounterCache.h"
#include "fboss/agent/test/HwTestHandle.h"
#include "fboss/agent/test/TestUtils.h"
Expand All @@ -15,6 +16,8 @@
#include <gtest/gtest.h>
#include "fboss/agent/GtestDefs.h"

using ::testing::_;
using ::testing::Return;
namespace facebook::fboss {
namespace {
constexpr auto kRemoteSwitchIdBegin = 4;
Expand Down Expand Up @@ -361,6 +364,44 @@ TYPED_TEST(DsfSubscriptionTest, DataUpdate) {
this->getRemoteSystemPorts()->size(), this->kNumRemoteSwitchAsics + 1));
}

TYPED_TEST(DsfSubscriptionTest, updateFailed) {
CounterCache counters(this->sw_);
this->createPublisher();
auto state = this->makeSwitchState();
this->publishSwitchState(state);

std::optional<std::map<SwitchID, std::shared_ptr<SystemPortMap>>>
recvSysPorts;
std::optional<std::map<SwitchID, std::shared_ptr<InterfaceMap>>> recvIntfs;
this->subscription_ = this->createSubscription();

WITH_RETRIES({
ASSERT_EVENTUALLY_EQ(
this->getRemoteSystemPorts()->size(), this->kNumRemoteSwitchAsics);
ASSERT_EVENTUALLY_EQ(
this->getRemoteInterfaces()->size(), this->kNumRemoteSwitchAsics);
EXPECT_EQ(this->dsfSessionState(), DsfSessionState::WAIT_FOR_REMOTE);
});
waitForStateUpdates(this->sw_);

// Fail HW update by returning current state
EXPECT_HW_CALL(this->sw_, stateChangedImpl(_))
.Times(::testing::AtLeast(1))
.WillOnce(Return(this->sw_->getState()));
auto sysPort2 = makeSysPort(
std::nullopt, SystemPortID(kSysPortRangeMin + 2), kRemoteSwitchIdBegin);
auto portMap = state->getSystemPorts()->modify(&state);
portMap->addNode(sysPort2, this->matcher());
this->publishSwitchState(state);
auto dsfUpdateFailedCounter =
SwitchStats::kCounterPrefix + "dsf_update_failed.sum.60";
WITH_RETRIES({
counters.update();
ASSERT_EVENTUALLY_TRUE(counters.checkExist(dsfUpdateFailedCounter));
ASSERT_EVENTUALLY_EQ(counters.value(dsfUpdateFailedCounter), 1);
});
}

TYPED_TEST(DsfSubscriptionTest, updateWithRollbackProtection) {
auto sysPorts = makeSysPortsForSwitchIds(
std::set<SwitchID>({SwitchID(kRemoteSwitchIdBegin)}), 2);
Expand Down

0 comments on commit b780b2e

Please sign in to comment.