diff --git a/integ/browser-tests/package.json b/integ/browser-tests/package.json index 8678bd95..f5fc1270 100644 --- a/integ/browser-tests/package.json +++ b/integ/browser-tests/package.json @@ -27,10 +27,10 @@ "@types/webpack": "^5.28.5", "fork-ts-checker-webpack-plugin": "^9.0.2", "html-webpack-plugin": "^5.5.3", - "puppeteer": "^21.5.0", + "puppeteer": "^21.5.1", "ts-loader": "^9.5.0", "tslib": "^2.6.2", - "type-fest": "^4.7.0", + "type-fest": "^4.7.1", "webpack": "^5.89.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^4.15.1" diff --git a/mk/package.json b/mk/package.json index dea4d84c..50bdc302 100644 --- a/mk/package.json +++ b/mk/package.json @@ -8,7 +8,7 @@ "js-yaml": "^4.1.0", "readlink": "^3.0.0", "split2": "^4.2.0", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" }, "dependencies": { "compare-versions": "6.1.0" diff --git a/packages/autoconfig/package.json b/packages/autoconfig/package.json index f0e54900..ba126b3c 100644 --- a/packages/autoconfig/package.json +++ b/packages/autoconfig/package.json @@ -43,6 +43,6 @@ "@types/koa": "^2.13.11", "@types/node-fetch": "^2.6.9", "koa": "^2.14.2", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" } } \ No newline at end of file diff --git a/packages/fw/src/readvertise.ts b/packages/fw/src/readvertise.ts index cf5282a2..18f727f2 100644 --- a/packages/fw/src/readvertise.ts +++ b/packages/fw/src/readvertise.ts @@ -75,7 +75,7 @@ export abstract class ReadvertiseDestination { this.readvertise = (fw as ForwarderImpl).readvertise; this.readvertise.destinations.add(this); for (const [name] of this.readvertise.announcements.associations()) { - this.queue.push(name); + this.advertise(name); } void this.process(); } diff --git a/packages/fw/tests/readvertise.t.ts b/packages/fw/tests/readvertise.t.ts index e5e6e127..4651786f 100644 --- a/packages/fw/tests/readvertise.t.ts +++ b/packages/fw/tests/readvertise.t.ts @@ -13,41 +13,76 @@ beforeEach(() => { }); class SimpleDest extends ReadvertiseDestination { - public override doAdvertise = vi.fn<[Name, {}], Promise>().mockResolvedValue(undefined); - public override doWithdraw = vi.fn<[Name, {}], Promise>().mockResolvedValue(undefined); + protected override doAdvertise = vi.fn<[Name, {}], Promise>().mockResolvedValue(undefined); + protected override doWithdraw = vi.fn<[Name, {}], Promise>().mockResolvedValue(undefined); - public readonly annadd = vi.fn<[Forwarder.AnnouncementEvent], void>(); - public readonly annrm = vi.fn<[Forwarder.AnnouncementEvent], void>(); + private hasEvents = false; + private readonly annadd = vi.fn<[Forwarder.AnnouncementEvent], void>(); + private readonly annrm = vi.fn<[Forwarder.AnnouncementEvent], void>(); public attachEventHandlers(fw: Forwarder): void { + this.hasEvents = true; fw.addEventListener("annadd", this.annadd); fw.addEventListener("annrm", this.annrm); } - public expectAdvertise(names: NameLike[]): void { - SimpleDest.check(this.doAdvertise, this.annadd, names); + public expectAdvertise(names: readonly NameLike[]): void { + SimpleDest.check(this.doAdvertise, this.hasEvents && this.annadd, names); } - public expectWithdraw(names: NameLike[]): void { - SimpleDest.check(this.doWithdraw, this.annrm, names); + public expectWithdraw(names: readonly NameLike[]): void { + SimpleDest.check(this.doWithdraw, this.hasEvents && this.annrm, names); } private static check( doFn: Mock<[Name, {}], Promise>, - onFn: Mock<[Forwarder.AnnouncementEvent], void>, - names: NameLike[], + onFn: false | Mock<[Forwarder.AnnouncementEvent], void>, + names: readonly NameLike[], ) { expect(doFn).toHaveBeenCalledTimes(names.length); - expect(onFn).toHaveBeenCalledTimes(names.length); + if (onFn) { + expect(onFn).toHaveBeenCalledTimes(names.length); + } + for (const [i, nameLike] of names.entries()) { expect(doFn.mock.calls[i]![0]).toEqualName(nameLike); - expect(onFn.mock.calls[i]![0].name).toEqualName(nameLike); + if (onFn) { + expect(onFn.mock.calls[i]![0].name).toEqualName(nameLike); + } } + doFn.mockClear(); - onFn.mockClear(); + if (onFn) { + onFn.mockClear(); + } } } +class StatefulDest extends ReadvertiseDestination<{ S: true }> { + constructor() { + super({ + minTimeout: 1, + maxTimeout: 1, + }); + } + + public override makeState = vi.fn().mockReturnValue({ S: true }); + + public doAdvertise = vi.fn().mockImplementationOnce(async () => { + await delay(90); + throw new Error("advertise error"); + }).mockImplementation(async () => { + await delay(90); + }); + + public doWithdraw = vi.fn().mockImplementationOnce(async () => { + await delay(90); + throw new Error("withdraw error"); + }).mockImplementation(async () => { + await delay(90); + }); +} + test("simple", async () => { const dest = new SimpleDest(); dest.enable(fw); @@ -92,31 +127,6 @@ test("simple", async () => { dest.expectAdvertise([]); }); -class StatefulDest extends ReadvertiseDestination<{ S: true }> { - constructor() { - super({ - minTimeout: 1, - maxTimeout: 1, - }); - } - - public override makeState = vi.fn().mockReturnValue({ S: true }); - - public doAdvertise = vi.fn().mockImplementationOnce(async () => { - await delay(90); - throw new Error("advertise error"); - }).mockImplementation(async () => { - await delay(90); - }); - - public doWithdraw = vi.fn().mockImplementationOnce(async () => { - await delay(90); - throw new Error("withdraw error"); - }).mockImplementation(async () => { - await delay(90); - }); -} - test("disable", async () => { const dest = new StatefulDest(); dest.enable(fw); @@ -132,6 +142,21 @@ test("disable", async () => { // no retry after closing }); +test("new dest", async () => { + const dest0 = new SimpleDest(); + dest0.enable(fw); + + const faceA = fw.addFace(new NoopFace()); + faceA.addAnnouncement("/A"); + await delay(5); + dest0.expectAdvertise(["/A"]); + + const dest1 = new SimpleDest(); + dest1.enable(fw); + await delay(5); + dest1.expectAdvertise(["/A"]); +}); + test("retry", async () => { const dest = new StatefulDest(); dest.enable(fw); diff --git a/packages/l3face/package.json b/packages/l3face/package.json index d447981b..469c5d9a 100644 --- a/packages/l3face/package.json +++ b/packages/l3face/package.json @@ -37,7 +37,7 @@ "retry": "^0.13.1", "streaming-iterables": "^8.0.1", "tslib": "^2.6.2", - "type-fest": "^4.7.0", + "type-fest": "^4.7.1", "typescript-event-target": "^1.1.0" }, "devDependencies": { diff --git a/packages/nac/package.json b/packages/nac/package.json index 1bc37cae..9c836f9b 100644 --- a/packages/nac/package.json +++ b/packages/nac/package.json @@ -37,7 +37,7 @@ "@yoursunny/asn1": "0.0.20200718", "mnemonist": "^0.39.5", "tslib": "^2.6.2", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" }, "devDependencies": { "@ndn/repo": "workspace:*" diff --git a/packages/ndncert/package.json b/packages/ndncert/package.json index 4cec872d..3ed69770 100644 --- a/packages/ndncert/package.json +++ b/packages/ndncert/package.json @@ -41,7 +41,7 @@ "nodemailer": "^6.9.7", "p-timeout": "^6.1.2", "tslib": "^2.6.2", - "type-fest": "^4.7.0", + "type-fest": "^4.7.1", "typescript-event-target": "^1.1.0" }, "devDependencies": { diff --git a/packages/nfdmgmt/package.json b/packages/nfdmgmt/package.json index abbfbe18..06edd5ea 100644 --- a/packages/nfdmgmt/package.json +++ b/packages/nfdmgmt/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@ndn/l3face": "workspace:*", "@ndn/node-transport": "workspace:*", - "type-fest": "^4.7.0", + "type-fest": "^4.7.1", "typescript-event-target": "^1.1.0" } } \ No newline at end of file diff --git a/packages/node-transport/package.json b/packages/node-transport/package.json index c685a490..8bf5f38f 100644 --- a/packages/node-transport/package.json +++ b/packages/node-transport/package.json @@ -27,7 +27,7 @@ "@ndn/l3face": "workspace:*", "event-iterator": "^2.0.0", "tslib": "^2.6.2", - "type-fest": "^4.7.0", + "type-fest": "^4.7.1", "url-format-lax": "^2.0.0", "url-parse-lax": "^5.0.0" }, diff --git a/packages/packet/package.json b/packages/packet/package.json index 7ff39019..7e39dcd9 100644 --- a/packages/packet/package.json +++ b/packages/packet/package.json @@ -31,7 +31,7 @@ "buffer-compare": "^1.1.1", "mnemonist": "^0.39.5", "tslib": "^2.6.2", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" }, "devDependencies": { "@types/buffer-compare": "^0.0.33" diff --git a/packages/repo-api/package.json b/packages/repo-api/package.json index 5a97c305..4b1aa889 100644 --- a/packages/repo-api/package.json +++ b/packages/repo-api/package.json @@ -47,6 +47,6 @@ "@types/tmp": "^0.2.6", "stream-mock": "^2.0.5", "tmp": "^0.2.1", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" } } \ No newline at end of file diff --git a/packages/segmented-object/package.json b/packages/segmented-object/package.json index 6ae31fb8..1f3aab3e 100644 --- a/packages/segmented-object/package.json +++ b/packages/segmented-object/package.json @@ -45,6 +45,6 @@ "@ndn/l3face": "workspace:*", "@ndn/repo-api": "workspace:*", "stream-mock": "^2.0.5", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" } } \ No newline at end of file diff --git a/packages/trust-schema/package.json b/packages/trust-schema/package.json index a11cadd8..ecd6cf14 100644 --- a/packages/trust-schema/package.json +++ b/packages/trust-schema/package.json @@ -33,7 +33,7 @@ "@ndn/util": "workspace:*", "mnemonist": "^0.39.5", "tslib": "^2.6.2", - "type-fest": "^4.7.0" + "type-fest": "^4.7.1" }, "devDependencies": { "@ndn/repo": "workspace:*",