Merge branch 'fix-wasm-tests' into 'main'

Fix wasm tests

See merge request veilid/veilid!326
This commit is contained in:
Christien Rioux 2024-10-19 23:12:23 +00:00
commit d88236b97f
4 changed files with 19 additions and 8 deletions

View File

@ -76,7 +76,7 @@ pub async fn test_attach_detach() {
pub async fn test_startup_shutdown_multiple() { pub async fn test_startup_shutdown_multiple() {
trace!("test_startup_shutdown_multiple: starting"); trace!("test_startup_shutdown_multiple: starting");
let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::<Vec<_>>(); let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::<Vec<_>>();
let mut apis = vec![]; let mut apis = vec![];
for ns in &namespaces { for ns in &namespaces {
@ -96,7 +96,7 @@ pub async fn test_startup_shutdown_multiple() {
pub async fn test_startup_shutdown_from_config_multiple() { pub async fn test_startup_shutdown_from_config_multiple() {
trace!("test_startup_from_config_multiple: starting"); trace!("test_startup_from_config_multiple: starting");
let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::<Vec<_>>(); let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::<Vec<_>>();
let mut apis = vec![]; let mut apis = vec![];
for ns in &namespaces { for ns in &namespaces {
let config = VeilidConfigInner { let config = VeilidConfigInner {
@ -136,7 +136,7 @@ pub async fn test_startup_shutdown_from_config_multiple() {
pub async fn test_attach_detach_multiple() { pub async fn test_attach_detach_multiple() {
trace!("test_attach_detach_multiple: --- test normal order ---"); trace!("test_attach_detach_multiple: --- test normal order ---");
let namespaces = (0..10).map(|x| format!("ns_{}", x)).collect::<Vec<_>>(); let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::<Vec<_>>();
let mut apis = vec![]; let mut apis = vec![];
for ns in &namespaces { for ns in &namespaces {
let (update_callback, config_callback) = setup_veilid_core_with_namespace(ns); let (update_callback, config_callback) = setup_veilid_core_with_namespace(ns);

View File

@ -4,6 +4,7 @@ name = "veilid-wasm"
version = "0.3.4" version = "0.3.4"
# --- # ---
description = "Veilid bindings for WebAssembly" description = "Veilid bindings for WebAssembly"
repository = "https://gitlab.com/veilid/veilid"
authors = ["Veilid Team <contact@veilid.com>"] authors = ["Veilid Team <contact@veilid.com>"]
license = "MPL-2.0" license = "MPL-2.0"
edition = "2021" edition = "2021"

View File

@ -12,7 +12,7 @@ import {
veilidCrypto, veilidCrypto,
} from 'veilid-wasm'; } from 'veilid-wasm';
import { textEncoder, textDecoder } from './utils/marshalling-utils'; import { textEncoder, textDecoder } from './utils/marshalling-utils';
import { asyncCallWithTimeout, waitForPublicAttachment } from './utils/wait-utils'; import { asyncCallWithTimeout, waitForPublicAttachment, waitForOfflineSubkeyWrite } from './utils/wait-utils';
describe('VeilidRoutingContext', () => { describe('VeilidRoutingContext', () => {
before('veilid startup', async () => { before('veilid startup', async () => {
@ -255,10 +255,13 @@ describe('VeilidRoutingContext', () => {
"Local", "Local",
); );
expect(inspectRes).toBeDefined(); 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.local_seqs).toEqual([0]);
expect(inspectRes.network_seqs).toEqual([]); expect(inspectRes.network_seqs).toEqual([]);
// Wait for synchronization
await waitForOfflineSubkeyWrite(routingContext, dhtRecord.key);
// Inspect network // Inspect network
const inspectRes2 = await routingContext.inspectDhtRecord( const inspectRes2 = await routingContext.inspectDhtRecord(
dhtRecord.key, dhtRecord.key,
@ -266,7 +269,8 @@ describe('VeilidRoutingContext', () => {
"SyncGet", "SyncGet",
); );
expect(inspectRes2).toBeDefined(); 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.local_seqs).toEqual([0]);
expect(inspectRes2.network_seqs).toEqual([0]); expect(inspectRes2.network_seqs).toEqual([0]);
}); });
@ -284,7 +288,7 @@ describe('VeilidRoutingContext', () => {
dhtRecord.key, dhtRecord.key,
); );
expect(inspectRes).toBeDefined(); 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.local_seqs).toEqual([0]);
expect(inspectRes.network_seqs).toEqual([]); expect(inspectRes.network_seqs).toEqual([]);
}); });

View File

@ -1,4 +1,4 @@
import { veilidClient } from 'veilid-wasm'; import { veilidClient, VeilidRoutingContext, TypedKey } from 'veilid-wasm';
export const waitForMs = (milliseconds: number) => { export const waitForMs = (milliseconds: number) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds)); return new Promise((resolve) => setTimeout(resolve, milliseconds));
@ -59,3 +59,9 @@ export const waitForDetached = async () => {
await waitForMs(1000); await waitForMs(1000);
} }
} }
export const waitForOfflineSubkeyWrite = async (routingContext: VeilidRoutingContext, key: TypedKey) => {
while ((await routingContext.inspectDhtRecord(key)).offline_subkeys.length != 0) {
await waitForMs(200);
}
}