Skip to content

Commit

Permalink
nfdmgmt,etc: move TestOptions to 2nd argument
Browse files Browse the repository at this point in the history
Vitest 1.3.0 deprecates TestOptions in 3rd argument of test().
  • Loading branch information
yoursunny committed Mar 8, 2024
1 parent 6d3d262 commit 0722b0f
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pkg/autoconfig/tests/network.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test("connectToNetwork", async () => {
expect(faces2).toHaveLength(2);
});

test("defaultGateway", async () => {
test("defaultGateway", { timeout: 10000 }, async () => {
await using fchServer = await FchServer.create(() => "127.0.0.1:7001,127.0.0.1:7002");
const mockGatewayResult: defaultGateway.Result<4> = {
gateway: "127.0.0.1",
Expand Down Expand Up @@ -108,7 +108,7 @@ test("defaultGateway", async () => {
expect(testConnection).toHaveBeenCalledTimes(3);
expect(calledWith6363).toBeTruthy();
expect(calledWith7004).toBeFalsy();
}, { timeout: 10000 });
});

test("connectFailure", async () => {
const testConnection = vi.fn<[FwFace], Promise<unknown>>()
Expand Down
8 changes: 4 additions & 4 deletions pkg/keychain/tests/key/encryption.t.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@ndn/packet/test-fixture/expect";

import { Component, Name } from "@ndn/packet";
import { Component, Name, ValidityPeriod } from "@ndn/packet";
import { crypto } from "@ndn/util";
import { expect, test } from "vitest";

import { AesBlockSize, AESCBC, AESCTR, AESGCM, Certificate, CounterIvChecker, createEncrypter, type EncryptionAlgorithm, EncryptionAlgorithmListFull, generateEncryptionKey, generateSigningKey, KeyChain, type NamedDecrypter, type NamedEncrypter, RSAOAEP, ValidityPeriod } from "../..";
import { AesBlockSize, AESCBC, AESCTR, AESGCM, Certificate, CounterIvChecker, createEncrypter, type EncryptionAlgorithm, EncryptionAlgorithmListFull, generateEncryptionKey, generateSigningKey, KeyChain, type NamedDecrypter, type NamedEncrypter, RSAOAEP } from "../..";

async function testEncryptDecrypt(encrypter: NamedEncrypter, decrypter: NamedDecrypter, aead: boolean) {
expect(encrypter.name).toEqualName(decrypter.name);
Expand Down Expand Up @@ -123,7 +123,7 @@ test.each([
await expect(dA.llDecrypt(cA1)).rejects.toThrow(); // counter not increasing
});

test("RSA-OAEP encrypt-decrypt", async () => {
test("RSA-OAEP encrypt-decrypt", { timeout: 10000 }, async () => {
const keyChain = KeyChain.createTemp(EncryptionAlgorithmListFull);
const name = new Name("/my/KEY/x");
await generateEncryptionKey(keyChain, name, RSAOAEP);
Expand All @@ -138,4 +138,4 @@ test("RSA-OAEP encrypt-decrypt", async () => {
});
const encrypter = await createEncrypter(cert, { algoList: EncryptionAlgorithmListFull });
await testEncryptDecrypt(encrypter, decrypter, true);
}, 10000);
});
8 changes: 4 additions & 4 deletions pkg/keychain/tests/key/signing.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ describe.each(EcCurve.Choices)("ECDSA %s", (curve) => {

describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => {
describe.each(TestSignVerify.PacketTable)("sign-verify %j", ({ Packet }) => {
test("", async () => {
test("", { timeout: 15000 }, async () => {
const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", RSA, { modulusLength });
const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", RSA, { modulusLength });

const record = await TestSignVerify.execute(Packet, pvtA, pubA, pvtB, pubB);
TestSignVerify.check(record, { deterministic: true });
expect(record.sA0.sigInfo.type).toBe(SigType.Sha256WithRsa);
expect(record.sA0.sigInfo.keyLocator).toHaveName(pvtA.name);
}, { timeout: 15000 });
});
});

test("load", async () => {
test("load", { timeout: 15000 }, async () => {
const keyChain = KeyChain.createTemp(SigningAlgorithmListFull);
const name = new Name("/my/KEY/x");
await generateSigningKey(keyChain, name, RSA, { modulusLength });
Expand All @@ -73,7 +73,7 @@ describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => {
expect(verifier.name).toEqualName(signer.name);
expect(verifier.sigType).toBe(SigType.Sha256WithRsa);
await verifier.verify(cert.data);
}, { timeout: 15000 });
});
});

describe("HMAC", () => {
Expand Down
18 changes: 9 additions & 9 deletions pkg/nac/tests/workflow.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect, test } from "vitest";

import { AccessManager, Consumer, Producer } from "..";

test("simple", async () => {
test("simple", { timeout: 10000 }, async () => {
using closers = new Closers();
const star = Bridge.star({ leaves: 3 }); // 0=AccessManager, 1=Producer, 2=Consumer
closers.push(...star);
Expand All @@ -20,14 +20,14 @@ test("simple", async () => {

const amName = new Name("/access/manager");
const amR = await makeRepoProducer({
pOpts: { fw: star[0].fwB },
pOpts: { fw: star[0]!.fwB },
reg: PrefixRegStatic(amName),
});
closers.push(amR);
const [amSigner, amVerifier] = await generateSigningKey(amName);
const [amOwnKdkEncrypter, amOwnKdkDecrypter] = await generateEncryptionKey(amName.append("kdk-encrypt"), RSAOAEP);
const am = AccessManager.create({
cOpts: { fw: star[0].fwB },
cOpts: { fw: star[0]!.fwB },
dataStore: amR.store,
prefix: amName,
keys: {
Expand All @@ -46,7 +46,7 @@ test("simple", async () => {
expect(kekHlookup.kek).toHaveName(kek.name);

const pR = await makeRepoProducer({
pOpts: { fw: star[1].fwB },
pOpts: { fw: star[1]!.fwB },
reg: PrefixRegStatic(new Name("/producer/ck-prefix")),
});
closers.push(pR);
Expand All @@ -63,7 +63,7 @@ test("simple", async () => {
const data = new Data(interest.name, appContent);
await pEncrypter.encrypt(data);
return data;
}, { fw: star[1].fwB, dataSigner: pSigner });
}, { fw: star[1]!.fwB, dataSigner: pSigner });
closers.push(pP);

const [cEncrypter, cDecrypter] = await generateEncryptionKey("/consumer", RSAOAEP);
Expand All @@ -74,14 +74,14 @@ test("simple", async () => {
publicKey: cEncrypter,
});
const cR = await makeRepoProducer({
pOpts: { fw: star[2].fwB },
pOpts: { fw: star[2]!.fwB },
reg: PrefixRegStatic(new Name("/consumer")),
}, [cCert.data]);
closers.push(cR);

const c = Consumer.create({
cOpts: {
fw: star[2].fwB,
fw: star[2]!.fwB,
modifyInterest: { lifetime: 100 }, // allow failed CK retrieval timeout faster
},
verifier: {
Expand All @@ -95,7 +95,7 @@ test("simple", async () => {
memberDecrypter: cDecrypter,
});
const appData = await consume("/data/part1/packet0", {
fw: star[2].fwB,
fw: star[2]!.fwB,
verifier: pVerifier,
});
expect(appData.content).not.toEqualUint8Array(appContent);
Expand All @@ -104,4 +104,4 @@ test("simple", async () => {
await kekH.grant(cCert.name);
await c.decrypt(appData);
expect(appData.content).toEqualUint8Array(appContent);
}, 10000);
});
8 changes: 4 additions & 4 deletions pkg/ndnsec/tests/keychain.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { test } from "vitest";

import { NdnsecKeyChain } from "..";

test.runIf(NdnsecKeyChain.supported)("KeyStore", async () => {
test.runIf(NdnsecKeyChain.supported)("KeyStore", { timeout: 20000 }, async () => {
using tmpDir = makeTmpDir();
const enabled: TestKeyStore.Enable = { HMAC: false, Ed25519: false };
const keyChain = new NdnsecKeyChain({ home: tmpDir.name });
const record = await TestKeyStore.execute(keyChain, enabled);
TestKeyStore.check(record, enabled);
}, 20000);
});

test.runIf(NdnsecKeyChain.supported)("CertStore", async () => {
test.runIf(NdnsecKeyChain.supported)("CertStore", { timeout: 20000 }, async () => {
using tmpDir = makeTmpDir();
const keyChain = new NdnsecKeyChain({ home: tmpDir.name });
const record = await TestCertStore.execute(keyChain);
TestCertStore.check(record);
}, 20000);
});
1 change: 1 addition & 0 deletions pkg/nfdmgmt/src/status-dataset-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function list<R>(arg1: string | StatusDataset<R>, arg2: any = {}, a
prefix = localhostPrefix,
} = opts;
const cOpts: ConsumerOptions = {
describe: "nfdmgmt",
...endpoint?.cOpts,
...cOptsInput,
verifier,
Expand Down
4 changes: 2 additions & 2 deletions pkg/nfdmgmt/tests/prefix-reg.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TABLE: Row[] = [
},
];

test.each(TABLE)("reg %#", async ({ faceIsLocal, expectedPrefix }) => {
test.each(TABLE)("reg %#", { timeout: 10000, retry: 3 }, async ({ faceIsLocal, expectedPrefix }) => {
const fw = Forwarder.create();
closers.push(fw);

Expand Down Expand Up @@ -110,7 +110,7 @@ test.each(TABLE)("reg %#", async ({ faceIsLocal, expectedPrefix }) => {
uplinkL3.dispatchTypedEvent("up", new Event("up"));
await delay(200);
expect(verbs).toHaveLength(6);
}, { timeout: 10000, retry: 3 });
});

test("preloadCert", async () => {
const [rootPvt, rootPub] = await generateSigningKey("/root");
Expand Down
4 changes: 2 additions & 2 deletions pkg/psync/tests/psync-full.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test.each([20, 50, 100])("many updates %d", async (count) => {
}
});

describe.each([4, 6])("many nodes %d", (count) => {
describe.each([4, 6])("many nodes %d", { timeout: 20000 }, (count) => {
test("", async () => {
const f = new Fixture(count);
await f.delayTick();
Expand All @@ -234,5 +234,5 @@ describe.each([4, 6])("many nodes %d", (count) => {
expect(node!.seqNum).toBe(1);
}
}
}, 20000);
});
});
4 changes: 2 additions & 2 deletions pkg/psync/tests/psync-partial.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function delayTick(multiple = 1): Promise<void> {
return delay(300 * multiple);
}

test("simple", async () => {
test("simple", { retry: 3 }, async () => {
const pub = new PartialPublisher({
p: makePSyncCompatParam(),
syncPrefix: new Name("/psync-test"),
Expand Down Expand Up @@ -79,4 +79,4 @@ test("simple", async () => {

pub.close();
sub.close();
}, { retry: 3 });
});
4 changes: 2 additions & 2 deletions pkg/segmented-object/tests/data-producer.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("listData", async () => {
expect(Buffer.concat(packets.map((data) => data.content))).toEqualUint8Array(objectBody);
});

test("DataTape insert", async () => {
test("DataTape insert", { timeout: 10000 }, async () => {
const src = new BufferChunkSource(objectBody);
const list = DataProducer.listData(src, new Name("/R"));

Expand All @@ -31,7 +31,7 @@ test("DataTape insert", async () => {
const packets = await collect(tape.listData());
packets.sort((a, b) => a.name.compare(b.name));
expect(Buffer.concat(packets.map((data) => data.content))).toEqualUint8Array(objectBody);
}, 10000);
});

test("bufferBehind bufferAhead", async () => {
let offset = 0;
Expand Down
4 changes: 2 additions & 2 deletions pkg/segmented-object/tests/serve-fetch.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ test("FwFace closing", async () => {
expect(Date.now() - t0).toBeLessThan(400);
});

test("congestion avoidance", async () => {
test("congestion avoidance", { timeout: 15000 }, async () => {
const relay: Bridge.RelayOptions = {
loss: 0.02,
delay: 50,
Expand All @@ -258,4 +258,4 @@ test("congestion avoidance", async () => {

const fetched = fetch("/R");
await expect(fetched).resolves.toEqualUint8Array(objectBody);
}, 15000);
});
8 changes: 4 additions & 4 deletions pkg/svs/tests/svsps.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function publishCheck(
abort.abort();
}

test("simple", async () => {
test("simple", { timeout: 20000 }, async () => {
const [signerE] = await generateSigningKey("/kE");

const syncA = await SvSync.create({ ...syncOpts, describe: "A" });
Expand Down Expand Up @@ -144,9 +144,9 @@ test("simple", async () => {
await publishCheck(pubB8, "/t/8", 100, undefined, [], [subC1, subC9, subDt, subD0]);
// bad mapping signature, but subC would not retrieve mapping
await publishCheck(pubB9, "/t/9", 100, undefined, [subC9], [subC1, subDt, subD0]);
}, { timeout: 20000 });
});

test("timed", async () => {
test("timed", { timeout: 20000 }, async () => {
const syncA = await SvSync.create({ ...syncOpts, describe: "A" });
const syncB = await SvSync.create({ ...syncOpts, describe: "B" });
closers.push(syncA, syncB);
Expand Down Expand Up @@ -208,4 +208,4 @@ test("timed", async () => {
await publishCheck(pubQ, "/N/3", 1000, makeNewEntry(), [sub0N, sub0F, sub1N, sub1F], [sub0P, sub1P]);
expect(filter0F).toHaveBeenCalledTimes(2);
expect(filter1F).toHaveBeenCalledTimes(4);
}, { timeout: 20000 });
});

0 comments on commit 0722b0f

Please sign in to comment.