blob: 2c648e947d2a78d36cc9438474fd5b6ccf5b7317 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -06003 * Copyright (c) 2014-2020, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070018 */
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050019
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/partial-producer.hpp"
21#include "PSync/consumer.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022
Davide Pesavento5b3cf762020-04-03 16:20:04 -040023#include "tests/boost-test.hpp"
24#include "tests/unit-test-time-fixture.hpp"
25
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050026#include <ndn-cxx/name.hpp>
27#include <ndn-cxx/util/dummy-client-face.hpp>
28
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029namespace psync {
30
31using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050032
33class PartialSyncFixture : public tests::UnitTestTimeFixture
34{
35public:
36 PartialSyncFixture()
Davide Pesavento5b3cf762020-04-03 16:20:04 -040037 : face(io, {true, true})
38 , syncPrefix("psync")
39 , userPrefix("testUser-0")
40 , numHelloDataRcvd(0)
41 , numSyncDataRcvd(0)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050042 {
43 producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix);
44 addUserNodes("testUser", 10);
45 }
46
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050047 ~PartialSyncFixture()
48 {
49 for (auto consumer : consumers) {
50 if (consumer) {
51 consumer->stop();
52 }
53 }
54 }
55
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050056 void
Davide Pesavento5b3cf762020-04-03 16:20:04 -040057 addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050058 {
Davide Pesavento5b3cf762020-04-03 16:20:04 -040059 consumerFaces[id] = std::make_shared<util::DummyClientFace>(io, util::DummyClientFace::Options{true, true});
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050060
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050061 if (linkToProducer) {
62 face.linkTo(*consumerFaces[id]);
63 }
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050064
Davide Pesavento5b3cf762020-04-03 16:20:04 -040065 consumers[id] = std::make_shared<Consumer>(syncPrefix, *consumerFaces[id],
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070066 [&, id] (const auto& availableSubs)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050067 {
68 numHelloDataRcvd++;
Ashlesh Gawandedeb73f82018-08-09 11:08:02 -050069 BOOST_CHECK(checkSubList(availableSubs));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050070
71 checkIBFUpdated(id);
72
73 for (const auto& sub : subscribeTo) {
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070074 auto it = availableSubs.find(sub);
75 consumers[id]->addSubscription(sub, it->second);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050076 }
77 consumers[id]->sendSyncInterest();
78 },
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070079 [&, id] (const auto& updates) {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050080 numSyncDataRcvd++;
81
82 checkIBFUpdated(id);
83
84 for (const auto& update : updates) {
85 BOOST_CHECK(consumers[id]->isSubscribed(update.prefix));
86 BOOST_CHECK_EQUAL(oldSeqMap.at(update.prefix) + 1, update.lowSeq);
87 BOOST_CHECK_EQUAL(producer->m_prefixes.at(update.prefix), update.highSeq);
88 BOOST_CHECK_EQUAL(consumers[id]->getSeqNo(update.prefix).value(), update.highSeq);
89 }
90 }, 40, 0.001);
91
92 advanceClocks(ndn::time::milliseconds(10));
93 }
94
95 void
96 checkIBFUpdated(int id)
97 {
98 Name emptyName;
99 producer->m_iblt.appendToName(emptyName);
100 BOOST_CHECK_EQUAL(consumers[id]->m_iblt, emptyName);
101 }
102
103 bool
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700104 checkSubList(const std::map<Name, uint64_t>& availableSubs) const
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500105 {
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400106 for (const auto& prefix : producer->m_prefixes) {
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700107 auto it = availableSubs.find(prefix.first);
108 if (it == availableSubs.end()) {
Ashlesh Gawandedeb73f82018-08-09 11:08:02 -0500109 return false;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500110 }
111 }
112 return true;
113 }
114
115 void
116 addUserNodes(const std::string& prefix, int numOfUserNodes)
117 {
118 // zeroth is added through constructor
119 for (int i = 1; i < numOfUserNodes; i++) {
120 producer->addUserNode(prefix + "-" + to_string(i));
121 }
122 }
123
124 void
125 publishUpdateFor(const std::string& prefix)
126 {
127 oldSeqMap = producer->m_prefixes;
128 producer->publishName(prefix);
129 advanceClocks(ndn::time::milliseconds(10));
130 }
131
132 void
133 updateSeqFor(const std::string& prefix, uint64_t seq)
134 {
135 oldSeqMap = producer->m_prefixes;
136 producer->updateSeqNo(prefix, seq);
137 }
138
139 util::DummyClientFace face;
140 Name syncPrefix;
141 Name userPrefix;
142
143 shared_ptr<PartialProducer> producer;
144 std::map <ndn::Name, uint64_t> oldSeqMap;
145
146 shared_ptr<Consumer> consumers[3];
147 shared_ptr<util::DummyClientFace> consumerFaces[3];
148 int numHelloDataRcvd;
149 int numSyncDataRcvd;
150};
151
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -0600152BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500153
154BOOST_AUTO_TEST_CASE(Simple)
155{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400156 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500157 addConsumer(0, subscribeTo);
158
159 consumers[0]->sendHelloInterest();
160 advanceClocks(ndn::time::milliseconds(10));
161 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
162
163 publishUpdateFor("testUser-2");
164 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
165 publishUpdateFor("testUser-3");
166 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
167 publishUpdateFor("testUser-2");
168 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
169}
170
171BOOST_AUTO_TEST_CASE(MissedUpdate)
172{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400173 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500174 addConsumer(0, subscribeTo);
175
176 consumers[0]->sendHelloInterest();
177 advanceClocks(ndn::time::milliseconds(10));
178 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
179
180 updateSeqFor("testUser-2", 3);
181 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
182
183 // The sync interest sent after hello will timeout
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700184 advanceClocks(ndn::time::milliseconds(999));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500185 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
186
187 // Next sync interest will bring back the sync data
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700188 advanceClocks(ndn::time::milliseconds(1));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500189 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
190}
191
192BOOST_AUTO_TEST_CASE(LateSubscription)
193{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400194 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500195 addConsumer(0, subscribeTo);
196
197 consumers[0]->sendHelloInterest();
198 advanceClocks(ndn::time::milliseconds(10));
199
200 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
201 publishUpdateFor("testUser-2");
202 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
203
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700204 consumers[0]->addSubscription("testUser-3", 0);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500205 consumers[0]->sendSyncInterest();
206 publishUpdateFor("testUser-3");
207 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
208}
209
210BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout)
211{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400212 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500213 addConsumer(0, subscribeTo);
214
215 consumers[0]->sendHelloInterest();
216 BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 0);
217 advanceClocks(ndn::time::milliseconds(10));
218 BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1);
219 advanceClocks(ndn::time::milliseconds(10), 100);
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700220 // The next Interest is sent after the first one immediately
221 BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500222 advanceClocks(ndn::time::milliseconds(10), 100);
223
224 int numSyncInterests = 0;
225 for (const auto& interest : consumerFaces[0]->sentInterests) {
226 if (interest.getName().getSubName(0, 2) == Name("/psync/sync")) {
227 numSyncInterests++;
228 }
229 }
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700230 BOOST_CHECK_EQUAL(numSyncInterests, 3);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500231 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
232}
233
234BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList)
235{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400236 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500237 addConsumer(0, subscribeTo);
238 addConsumer(1, subscribeTo);
239 addConsumer(2, subscribeTo);
240
241 consumers[0]->sendHelloInterest();
242 consumers[1]->sendHelloInterest();
243 consumers[2]->sendHelloInterest();
244 advanceClocks(ndn::time::milliseconds(10));
245
246 BOOST_CHECK_EQUAL(numHelloDataRcvd, 3);
247
248 publishUpdateFor("testUser-2");
249 BOOST_CHECK_EQUAL(numSyncDataRcvd, 3);
250
251 publishUpdateFor("testUser-3");
252 BOOST_CHECK_EQUAL(numSyncDataRcvd, 3);
253}
254
255BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList)
256{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400257 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500258 addConsumer(0, subscribeTo);
259
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400260 std::vector<std::string> subscribeTo1{"testUser-1", "testUser-3", "testUser-5"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500261 addConsumer(1, subscribeTo1);
262
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400263 std::vector<std::string> subscribeTo2{"testUser-2", "testUser-3"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500264 addConsumer(2, subscribeTo2);
265
266 consumers[0]->sendHelloInterest();
267 consumers[1]->sendHelloInterest();
268 consumers[2]->sendHelloInterest();
269 advanceClocks(ndn::time::milliseconds(10));
270
271 BOOST_CHECK_EQUAL(numHelloDataRcvd, 3);
272
273 publishUpdateFor("testUser-2");
274 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
275
276 numSyncDataRcvd = 0;
277 publishUpdateFor("testUser-3");
278 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
279}
280
281BOOST_AUTO_TEST_CASE(ReplicatedProducer)
282{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400283 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500284 addConsumer(0, subscribeTo);
285
286 consumers[0]->sendHelloInterest();
287 advanceClocks(ndn::time::milliseconds(10));
288 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
289
290 publishUpdateFor("testUser-2");
291 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
292
293 // Link to first producer goes down
294 face.unlink();
295
296 util::DummyClientFace face2(io, {true, true});
297 PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix);
298 for (int i = 1; i < 10; i++) {
299 replicatedProducer.addUserNode("testUser-" + to_string(i));
300 }
301 advanceClocks(ndn::time::milliseconds(10));
302 replicatedProducer.publishName("testUser-2");
303 // Link to a replicated producer comes up
304 face2.linkTo(*consumerFaces[0]);
305
306 BOOST_CHECK_EQUAL(face2.sentData.size(), 0);
307
308 // Update in first producer as well so consumer on sync data
309 // callback checks still pass
310 publishUpdateFor("testUser-2");
311 replicatedProducer.publishName("testUser-2");
312 advanceClocks(ndn::time::milliseconds(15), 100);
313 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
314 BOOST_CHECK_EQUAL(face2.sentData.size(), 1);
315}
316
317BOOST_AUTO_TEST_CASE(ApplicationNack)
318{
319 // 50 is more than expected number of entries of 40 in the producer's IBF
320 addUserNodes("testUser", 50);
321
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400322 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500323 addConsumer(0, subscribeTo);
324
325 consumers[0]->sendHelloInterest();
326 advanceClocks(ndn::time::milliseconds(10));
327 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
328
329 publishUpdateFor("testUser-2");
330 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
331
332 oldSeqMap = producer->m_prefixes;
333 for (int i = 0; i < 50; i++) {
334 ndn::Name prefix("testUser-" + to_string(i));
335 producer->updateSeqNo(prefix, producer->getSeqNo(prefix).value() + 1);
336 }
337 // Next sync interest should trigger the nack
338 advanceClocks(ndn::time::milliseconds(15), 100);
339
Ashlesh Gawandea9296472018-08-04 08:21:39 -0500340 // Application should have been notified that new data is available
341 // from the hello itself.
342 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500343
344 bool nackRcvd = false;
345 for (const auto& data : face.sentData) {
346 if (data.getContentType() == ndn::tlv::ContentType_Nack) {
347 nackRcvd = true;
348 break;
349 }
350 }
351 BOOST_CHECK(nackRcvd);
352
Ashlesh Gawandea9296472018-08-04 08:21:39 -0500353 publishUpdateFor("testUser-4");
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500354 advanceClocks(ndn::time::milliseconds(10));
Ashlesh Gawandea9296472018-08-04 08:21:39 -0500355 BOOST_CHECK_EQUAL(numSyncDataRcvd, 3);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500356}
357
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500358BOOST_AUTO_TEST_CASE(SegmentedHello)
359{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400360 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500361 addConsumer(0, subscribeTo);
362
363 addUserNodes("testUser", 400);
364
365 consumers[0]->sendHelloInterest();
366 advanceClocks(ndn::time::milliseconds(10));
367 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600368
369 // Simulate sending delayed interest for second segment
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400370 BOOST_REQUIRE(!face.sentData.empty());
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600371 Name dataName = face.sentData.back().getName();
372 face.sentData.clear();
373 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2);
374
375 advanceClocks(ndn::time::milliseconds(1000));
376 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0);
377
378 producer->onHelloInterest(consumers[0]->m_helloInterestPrefix, Interest(dataName));
379 advanceClocks(ndn::time::milliseconds(10));
380 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2);
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400381 BOOST_REQUIRE(!face.sentData.empty());
382 BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1);
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500383}
384
385BOOST_AUTO_TEST_CASE(SegmentedSync)
386{
387 ndn::Name longNameToExceedDataSize;
388 for (int i = 0; i < 100; i++) {
389 longNameToExceedDataSize.append("test-" + std::to_string(i));
390 }
391 addUserNodes(longNameToExceedDataSize.toUri(), 10);
392
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400393 std::vector<std::string> subscribeTo;
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500394 for (int i = 1; i < 10; i++) {
395 subscribeTo.push_back(longNameToExceedDataSize.toUri() + "-" + to_string(i));
396 }
397 addConsumer(0, subscribeTo);
398
399 consumers[0]->sendHelloInterest();
400 advanceClocks(ndn::time::milliseconds(10));
401 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
402
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600403 // To be used later to simulate sending delayed segmented interest
404 ndn::Name syncInterestName(consumers[0]->m_syncInterestPrefix);
405 consumers[0]->m_bloomFilter.appendToName(syncInterestName);
406 syncInterestName.append(consumers[0]->m_iblt);
407 syncInterestName.appendVersion();
408 syncInterestName.appendSegment(1);
409
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500410 oldSeqMap = producer->m_prefixes;
411 for (int i = 1; i < 10; i++) {
412 producer->updateSeqNo(longNameToExceedDataSize.toUri() + "-" + to_string(i), 1);
413 }
414
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700415 advanceClocks(ndn::time::milliseconds(999));
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500416 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
417
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700418 advanceClocks(ndn::time::milliseconds(1));
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500419 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600420
421 // Simulate sending delayed interest for second segment
422 face.sentData.clear();
423 consumerFaces[0]->sentData.clear();
424
425 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2);
426
427 advanceClocks(ndn::time::milliseconds(2000));
428 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0);
429
430 producer->onSyncInterest(consumers[0]->m_syncInterestPrefix, Interest(syncInterestName));
431 advanceClocks(ndn::time::milliseconds(10));
432 BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2);
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400433 BOOST_REQUIRE(!face.sentData.empty());
434 BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1);
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500435}
436
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700437BOOST_AUTO_TEST_CASE(DelayedSubscription) // #5122
438{
439 publishUpdateFor("testUser-2");
440 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4"};
441 addConsumer(0, subscribeTo);
442
443 consumers[0]->sendHelloInterest();
444 advanceClocks(ndn::time::milliseconds(10));
445 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
446
447 // Application came up late and subscribed to testUser-2
448 // after Producer had already published the first update.
449 // So by default Consumer will let the application know that
450 // the prefix it subscribed to has already some updates
451 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
452}
453
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500454BOOST_AUTO_TEST_SUITE_END()
455
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -0600456} // namespace psync