|
| 1 | +#include "RedisChannel.h" |
| 2 | +#include "sairediscommon.h" |
| 3 | + |
| 4 | +#include "swss/notificationproducer.h" |
| 5 | + |
| 6 | +#include <gtest/gtest.h> |
| 7 | + |
| 8 | +#include <memory> |
| 9 | + |
| 10 | +using namespace sairedis; |
| 11 | + |
| 12 | +static std::string g_op; |
| 13 | +static std::string g_data; |
| 14 | + |
| 15 | +static void callback( |
| 16 | + _In_ const std::string& op, |
| 17 | + _In_ const std::string& data, |
| 18 | + _In_ const std::vector<swss::FieldValueTuple>& values) |
| 19 | +{ |
| 20 | + SWSS_LOG_ENTER(); |
| 21 | + |
| 22 | + g_op = op; |
| 23 | + g_data = data; |
| 24 | +} |
| 25 | + |
| 26 | +TEST(RedisChannel, reset) |
| 27 | +{ |
| 28 | + RedisChannel rc("ASIC_DB", callback); |
| 29 | + |
| 30 | + EXPECT_NE(nullptr, rc.getDbConnector()); |
| 31 | +} |
| 32 | + |
| 33 | +TEST(RedisChannel, notificationThreadFunction) |
| 34 | +{ |
| 35 | + RedisChannel rc("ASIC_DB", callback); |
| 36 | + |
| 37 | + rc.setResponseTimeout(10); |
| 38 | + |
| 39 | + auto db = std::make_shared<swss::DBConnector>("ASIC_DB", 0); |
| 40 | + |
| 41 | + swss::NotificationProducer p(db.get(), REDIS_TABLE_NOTIFICATIONS); |
| 42 | + |
| 43 | + std::vector<swss::FieldValueTuple> vals; |
| 44 | + p.send("foo", "bar", vals); |
| 45 | + |
| 46 | + usleep(200*1000); |
| 47 | + |
| 48 | + EXPECT_EQ(g_op, "foo"); |
| 49 | +} |
| 50 | + |
| 51 | +TEST(RedisChannel, flush) |
| 52 | +{ |
| 53 | + RedisChannel rc("ASIC_DB", callback); |
| 54 | + |
| 55 | + rc.flush(); |
| 56 | +} |
0 commit comments