Skip to content

Commit 1cbe883

Browse files
authored
Merge branch 'master' into v6erspan
2 parents 51592dc + 766e755 commit 1cbe883

7 files changed

Lines changed: 90 additions & 9 deletions

File tree

orchagent/orch.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,12 @@ void Consumer::execute()
242242
// ConsumerBase::execute_impl<swss::ConsumerTableBase>();
243243
SWSS_LOG_ENTER();
244244

245-
size_t update_size = 0;
246245
auto table = static_cast<swss::ConsumerTableBase *>(getSelectable());
247-
do
248-
{
249-
std::deque<KeyOpFieldsValuesTuple> entries;
250-
table->pops(entries);
251-
update_size = addToSync(entries);
252-
} while (update_size != 0);
246+
std::deque<KeyOpFieldsValuesTuple> entries;
247+
table->pops(entries);
248+
249+
// add to sync
250+
addToSync(entries);
253251

254252
drain();
255253
}

tests/dash/dash_db.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dvslib.dvs_common import wait_for_result
33
import typing
44
import pytest
5+
import time
56

67
from dash_api.appliance_pb2 import *
78
from dash_api.vnet_pb2 import *
@@ -58,9 +59,11 @@ def __setitem__(self, key: str, pairs: typing.Union[dict, list, tuple]):
5859
for k, v in pairs:
5960
pairs_str.append((to_string(k), to_string(v)))
6061
self.set(key, pairs_str)
62+
time.sleep(1)
6163

6264
def __delitem__(self, key: str):
6365
self.delete(str(key))
66+
time.sleep(1)
6467

6568

6669
class Table(swsscommon.Table):

tests/dash/test_dash_acl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ def __setitem__(self, key: str, pairs: Union[dict, list, tuple]):
8787
pairs_str.append((to_string(k), to_string(v)))
8888
self.table.set(key, pairs_str)
8989
self.keys.add(key)
90+
time.sleep(1)
9091

9192
def __delitem__(self, key: str):
9293
self.table.delete(str(key))
9394
self.keys.discard(key)
95+
time.sleep(1)
9496

9597
def get_keys(self):
9698
return self.keys

tests/dvslib/dvs_hash.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Utilities for interacting with HASH objects when writing VS tests."""
22
from typing import Dict, List
3+
import time
34

45

56
class DVSHash:
@@ -21,6 +22,7 @@ def update_switch_hash(
2122
) -> None:
2223
"""Update switch hash global in Config DB."""
2324
self.config_db.update_entry(self.CDB_SWITCH_HASH, self.KEY_SWITCH_HASH_GLOBAL, qualifiers)
25+
time.sleep(1)
2426

2527
def get_hash_ids(
2628
self,

tests/mock_tests/consumer_ut.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ namespace consumer_test
1010
{
1111
using namespace std;
1212

13+
class TestOrch : public Orch
14+
{
15+
public:
16+
TestOrch(swss::DBConnector *db, string tableName)
17+
:Orch(db, tableName),
18+
m_notification_count(0)
19+
{
20+
}
21+
22+
void doTask(Consumer& consumer)
23+
{
24+
std::cout << "TestOrch::doTask " << consumer.m_toSync.size() << std::endl;
25+
m_notification_count += consumer.m_toSync.size();
26+
consumer.m_toSync.clear();
27+
}
28+
29+
long m_notification_count;
30+
};
31+
1332
struct ConsumerTest : public ::testing::Test
1433
{
1534
shared_ptr<swss::DBConnector> m_app_db;
@@ -322,4 +341,31 @@ namespace consumer_test
322341
validate_syncmap(consumer->m_toSync, 1, key, exp_kofv);
323342

324343
}
344+
345+
TEST_F(ConsumerTest, ConsumerPops_notification_count)
346+
{
347+
int consumer_pops_batch_size = 10;
348+
TestOrch test_orch(m_config_db.get(), "CFG_TEST_TABLE");
349+
Consumer test_consumer(
350+
new swss::ConsumerStateTable(m_config_db.get(), "CFG_TEST_TABLE", consumer_pops_batch_size, 1), &test_orch, "CFG_TEST_TABLE");
351+
swss::ProducerStateTable producer_table(m_config_db.get(), "CFG_TEST_TABLE");
352+
353+
m_config_db->flushdb();
354+
for (int notification_count = 0; notification_count< consumer_pops_batch_size*2; notification_count++)
355+
{
356+
std::vector<FieldValueTuple> fields;
357+
FieldValueTuple t("test_field", "test_value");
358+
fields.push_back(t);
359+
producer_table.set(std::to_string(notification_count), fields);
360+
361+
cout << "ConsumerPops_notification_count:: add key: " << notification_count << endl;
362+
}
363+
364+
// consumer should pops consumer_pops_batch_size notifications
365+
test_consumer.execute();
366+
ASSERT_EQ(test_orch.m_notification_count, consumer_pops_batch_size);
367+
368+
test_consumer.execute();
369+
ASSERT_EQ(test_orch.m_notification_count, consumer_pops_batch_size*2);
370+
}
325371
}

tests/mock_tests/mock_consumerstatetable.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,34 @@ namespace swss
77
TableName_KeySet(tableName)
88
{
99
}
10+
11+
void ConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const std::string& /*prefix*/)
12+
{
13+
int count = 0;
14+
swss::Table table(getDbConnector(), getTableName());
15+
std::vector<std::string> keys;
16+
table.getKeys(keys);
17+
for (const auto &key: keys)
18+
{
19+
// pop with batch size
20+
if (count < POP_BATCH_SIZE)
21+
{
22+
count++;
23+
}
24+
else
25+
{
26+
break;
27+
}
28+
29+
KeyOpFieldsValuesTuple kco;
30+
kfvKey(kco) = key;
31+
kfvOp(kco) = SET_COMMAND;
32+
if (!table.get(key, kfvFieldsValues(kco)))
33+
{
34+
continue;
35+
}
36+
table.del(key);
37+
vkco.push_back(kco);
38+
}
39+
}
1040
}

tests/test_ipv6_link_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def test_NeighborAddRemoveIpv6LinkLocal(self, dvs, testlog):
5959
time.sleep(2)
6060

6161
# Neigh entries should contain Ipv6-link-local neighbors, should be 4
62-
neigh_entries = self.pdb.get_keys("NEIGH_TABLE")
63-
assert (len(neigh_entries) == 4)
62+
self.pdb.wait_for_n_keys("NEIGH_TABLE", 4)
6463

6564
found_entry = False
65+
neigh_entries = self.pdb.get_keys("NEIGH_TABLE")
6666
for key in neigh_entries:
6767
if (key.find("Ethernet4:2001::2") or key.find("Ethernet0:2000::2")):
6868
found_entry = True

0 commit comments

Comments
 (0)