From 8cdbf9a461b48796fc8d7863328e4ccec5d40024 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 19 Oct 2024 23:12:23 +0000 Subject: [PATCH] Fix wasm tests --- veilid-core/src/tests/common/test_veilid_core.rs | 6 +++--- veilid-wasm/Cargo.toml | 1 + veilid-wasm/tests/src/VeilidRoutingContext.test.ts | 12 ++++++++---- veilid-wasm/tests/src/utils/wait-utils.ts | 8 +++++++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/veilid-core/src/tests/common/test_veilid_core.rs b/veilid-core/src/tests/common/test_veilid_core.rs index 5a269a9f..e54038d7 100644 --- a/veilid-core/src/tests/common/test_veilid_core.rs +++ b/veilid-core/src/tests/common/test_veilid_core.rs @@ -76,7 +76,7 @@ pub async fn test_attach_detach() { pub async fn test_startup_shutdown_multiple() { trace!("test_startup_shutdown_multiple: starting"); - let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::>(); + let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::>(); let mut apis = vec![]; for ns in &namespaces { @@ -96,7 +96,7 @@ pub async fn test_startup_shutdown_multiple() { pub async fn test_startup_shutdown_from_config_multiple() { trace!("test_startup_from_config_multiple: starting"); - let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::>(); + let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::>(); let mut apis = vec![]; for ns in &namespaces { let config = VeilidConfigInner { @@ -136,7 +136,7 @@ pub async fn test_startup_shutdown_from_config_multiple() { pub async fn test_attach_detach_multiple() { trace!("test_attach_detach_multiple: --- test normal order ---"); - let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::>(); + let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::>(); let mut apis = vec![]; for ns in &namespaces { let (update_callback, config_callback) = setup_veilid_core_with_namespace(ns); diff --git a/veilid-wasm/Cargo.toml b/veilid-wasm/Cargo.toml index 7316b697..4f0ae832 100644 --- a/veilid-wasm/Cargo.toml +++ b/veilid-wasm/Cargo.toml @@ -4,6 +4,7 @@ name = "veilid-wasm" version = "0.3.4" # --- description = "Veilid bindings for WebAssembly" +repository = "https://gitlab.com/veilid/veilid" authors = ["Veilid Team "] license = "MPL-2.0" edition = "2021" diff --git a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts index cb9e4795..4bdacb36 100644 --- a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts +++ b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts @@ -12,7 +12,7 @@ import { veilidCrypto, } from 'veilid-wasm'; import { textEncoder, textDecoder } from './utils/marshalling-utils'; -import { asyncCallWithTimeout, waitForPublicAttachment } from './utils/wait-utils'; +import { asyncCallWithTimeout, waitForPublicAttachment, waitForOfflineSubkeyWrite } from './utils/wait-utils'; describe('VeilidRoutingContext', () => { before('veilid startup', async () => { @@ -255,10 +255,13 @@ describe('VeilidRoutingContext', () => { "Local", ); expect(inspectRes).toBeDefined(); - expect(inspectRes.subkeys).toEqual([[0, 0]]); + expect(inspectRes.subkeys.concat(inspectRes.offline_subkeys)).toEqual([[0, 0]]); expect(inspectRes.local_seqs).toEqual([0]); expect(inspectRes.network_seqs).toEqual([]); + // Wait for synchronization + await waitForOfflineSubkeyWrite(routingContext, dhtRecord.key); + // Inspect network const inspectRes2 = await routingContext.inspectDhtRecord( dhtRecord.key, @@ -266,7 +269,8 @@ describe('VeilidRoutingContext', () => { "SyncGet", ); expect(inspectRes2).toBeDefined(); - expect(inspectRes2.subkeys).toEqual([[0, 0]]); + expect(inspectRes.subkeys).toEqual([[0, 0]]); + expect(inspectRes.offline_subkeys).toEqual([]); expect(inspectRes2.local_seqs).toEqual([0]); expect(inspectRes2.network_seqs).toEqual([0]); }); @@ -284,7 +288,7 @@ describe('VeilidRoutingContext', () => { dhtRecord.key, ); expect(inspectRes).toBeDefined(); - expect(inspectRes.subkeys).toEqual([[0, 0]]); + expect(inspectRes.subkeys.concat(inspectRes.offline_subkeys)).toEqual([[0, 0]]); expect(inspectRes.local_seqs).toEqual([0]); expect(inspectRes.network_seqs).toEqual([]); }); diff --git a/veilid-wasm/tests/src/utils/wait-utils.ts b/veilid-wasm/tests/src/utils/wait-utils.ts index 4b69bd09..c14886cb 100644 --- a/veilid-wasm/tests/src/utils/wait-utils.ts +++ b/veilid-wasm/tests/src/utils/wait-utils.ts @@ -1,4 +1,4 @@ -import { veilidClient } from 'veilid-wasm'; +import { veilidClient, VeilidRoutingContext, TypedKey } from 'veilid-wasm'; export const waitForMs = (milliseconds: number) => { return new Promise((resolve) => setTimeout(resolve, milliseconds)); @@ -59,3 +59,9 @@ export const waitForDetached = async () => { await waitForMs(1000); } } + +export const waitForOfflineSubkeyWrite = async (routingContext: VeilidRoutingContext, key: TypedKey) => { + while ((await routingContext.inspectDhtRecord(key)).offline_subkeys.length != 0) { + await waitForMs(200); + } +}