diff --git a/examples/smoke-test/scripts/connect.ts b/examples/smoke-test/scripts/connect.ts index 962acb058..7c8e6898c 100644 --- a/examples/smoke-test/scripts/connect.ts +++ b/examples/smoke-test/scripts/connect.ts @@ -2,37 +2,40 @@ import { createClient } from "rivetkit/client"; import type { Registry } from "../src/registry"; async function main() { - const client = createClient("http://localhost:6420"); + const client = createClient(); - const counter = client.counter.getOrCreate().connect(); + const counter = client.counter.getOrCreate("foo").connect(); counter.on("newCount", (count: number) => console.log("Event:", count)); - - for (let i = 0; i < 5; i++) { - const out = await counter.increment(5); - console.log("RPC:", out); - - await new Promise((resolve) => setTimeout(resolve, 1000)); - } - - await new Promise((resolve) => setTimeout(resolve, 2000)); - await counter.dispose(); - - await new Promise((resolve) => setTimeout(resolve, 200)); - - const counter2 = client.counter.getOrCreate().connect(); - - counter2.on("newCount", (count: number) => console.log("Event:", count)); - - for (let i = 0; i < 5; i++) { - const out = await counter2.increment(5); - console.log("RPC:", out); - - await new Promise((resolve) => setTimeout(resolve, 1000)); - } - - await new Promise((resolve) => setTimeout(resolve, 2000)); - await counter2.dispose(); + await counter.increment(1); + + setInterval(() => {}, 1000); + + // for (let i = 0; i < 5; i++) { + // const out = await counter.increment(5); + // console.log("RPC:", out); + // + // await new Promise((resolve) => setTimeout(resolve, 1000)); + // } + // + // await new Promise((resolve) => setTimeout(resolve, 2000)); + // await counter.dispose(); + // + // await new Promise((resolve) => setTimeout(resolve, 200)); + // + // const counter2 = client.counter.getOrCreate().connect(); + // + // counter2.on("newCount", (count: number) => console.log("Event:", count)); + // + // for (let i = 0; i < 5; i++) { + // const out = await counter2.increment(5); + // console.log("RPC:", out); + // + // await new Promise((resolve) => setTimeout(resolve, 1000)); + // } + // + // await new Promise((resolve) => setTimeout(resolve, 2000)); + // await counter2.dispose(); } main(); diff --git a/examples/smoke-test/src/smoke-test/index.ts b/examples/smoke-test/src/smoke-test/index.ts index 469f75016..0fecf729c 100644 --- a/examples/smoke-test/src/smoke-test/index.ts +++ b/examples/smoke-test/src/smoke-test/index.ts @@ -66,12 +66,12 @@ function logProgress({ startedCount - (successCount + failureCount), ); console.log( - `progress: success=${successCount}, failures=${failureCount}, pending=${pendingCount}, remaining=${remainingCount}, duration(ms): avg=${stats.average.toFixed(2)}, median=${stats.median.toFixed(2)}, min=${stats.min.toFixed(2)}, max=${stats.max.toFixed(2)}`, + `progress: success=${successCount}, failures=${failureCount}, pending=${pendingCount}, remaining=${remainingCount}, samples=${iterationDurations.length}, duration(ms): avg=${stats.average.toFixed(2)}, median=${stats.median.toFixed(2)}, min=${stats.min.toFixed(2)}, max=${stats.max.toFixed(2)}`, ); } async function main() { - const client = createClient("http://localhost:6420"); + const client = createClient(); const testId = randomUUID(); const errors: SmokeTestError[] = []; let successCount = 0; @@ -130,7 +130,7 @@ async function main() { const finalStats = calculateDurationStats(iterationDurations); console.log( - `iteration duration stats (ms): avg=${finalStats.average.toFixed(2)}, median=${finalStats.median.toFixed(2)}, min=${finalStats.min.toFixed(2)}, max=${finalStats.max.toFixed(2)}`, + `iteration duration stats (ms): samples=${iterationDurations.length}, avg=${finalStats.average.toFixed(2)}, median=${finalStats.median.toFixed(2)}, min=${finalStats.min.toFixed(2)}, max=${finalStats.max.toFixed(2)}`, ); if (errors.length > 0) { diff --git a/examples/smoke-test/src/smoke-test/spawn-actor.ts b/examples/smoke-test/src/smoke-test/spawn-actor.ts index b62103935..2e2a7c7b8 100644 --- a/examples/smoke-test/src/smoke-test/spawn-actor.ts +++ b/examples/smoke-test/src/smoke-test/spawn-actor.ts @@ -28,27 +28,33 @@ export async function spawnActor({ onSuccess, onFailure, }: SpawnActorOptions): Promise { - const iterationStart = performance.now(); let succeeded = false; try { - const key = ["test", testId, index.toString()]; - const counter = client.counter.getOrCreate(key).connect(); - await counter.increment(1); - await counter.dispose(); + for (let i = 0; i < 20; i++) { + // Connect to actor + const connMethod = Math.random() > 0.5 ? "http" : "websocket"; + const iterationStart = performance.now(); + if (connMethod === "websocket") { + const key = ["test", testId, index.toString()]; + const counter = client.counter.getOrCreate(key).connect(); + await counter.increment(1); + await counter.dispose(); + } else if (connMethod === "http") { + const key = ["test", testId, index.toString()]; + const counter = client.counter.getOrCreate(key); + await counter.increment(1); + } + const iterationEnd = performance.now(); + const iterationDuration = iterationEnd - iterationStart; + iterationDurations.push(iterationDuration); - // Immediately reconnect - const counter2 = client.counter.getOrCreate(key).connect(); - await counter2.increment(1); - await counter2.dispose(); - - // Wait for actor to sleep - await new Promise((res) => setTimeout(res, 1000)); - - // Reconnect after sleep - const counter3 = client.counter.getOrCreate(key).connect(); - await counter3.increment(1); - await counter3.dispose(); + // Wait for actor to sleep (if > 500 ms) + const sleepTime = 100 + Math.random() * 800; + console.log("sleeping", sleepTime); + // const sleepTime = 1000; + await new Promise((res) => setTimeout(res, sleepTime)); + } succeeded = true; onSuccess(); @@ -58,8 +64,5 @@ export async function spawnActor({ } if (succeeded) { - const iterationEnd = performance.now(); - const iterationDuration = iterationEnd - iterationStart; - iterationDurations.push(iterationDuration); } }