Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions examples/smoke-test/scripts/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ import { createClient } from "rivetkit/client";
import type { Registry } from "../src/registry";

async function main() {
const client = createClient<Registry>("http://localhost:6420");
const client = createClient<Registry>();

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();
6 changes: 3 additions & 3 deletions examples/smoke-test/src/smoke-test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Registry>("http://localhost:6420");
const client = createClient<Registry>();
const testId = randomUUID();
const errors: SmokeTestError[] = [];
let successCount = 0;
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 23 additions & 20 deletions examples/smoke-test/src/smoke-test/spawn-actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,33 @@ export async function spawnActor({
onSuccess,
onFailure,
}: SpawnActorOptions): Promise<void> {
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();
Expand All @@ -58,8 +64,5 @@ export async function spawnActor({
}

if (succeeded) {
const iterationEnd = performance.now();
const iterationDuration = iterationEnd - iterationStart;
iterationDurations.push(iterationDuration);
}
}
Loading