Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 60e430e

Browse files
authored
chore(core): improve somke test (#1372)
1 parent a1c6620 commit 60e430e

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed

examples/smoke-test/scripts/connect.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,40 @@ import { createClient } from "rivetkit/client";
22
import type { Registry } from "../src/registry";
33

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

7-
const counter = client.counter.getOrCreate().connect();
7+
const counter = client.counter.getOrCreate("foo").connect();
88

99
counter.on("newCount", (count: number) => console.log("Event:", count));
10-
11-
for (let i = 0; i < 5; i++) {
12-
const out = await counter.increment(5);
13-
console.log("RPC:", out);
14-
15-
await new Promise((resolve) => setTimeout(resolve, 1000));
16-
}
17-
18-
await new Promise((resolve) => setTimeout(resolve, 2000));
19-
await counter.dispose();
20-
21-
await new Promise((resolve) => setTimeout(resolve, 200));
22-
23-
const counter2 = client.counter.getOrCreate().connect();
24-
25-
counter2.on("newCount", (count: number) => console.log("Event:", count));
26-
27-
for (let i = 0; i < 5; i++) {
28-
const out = await counter2.increment(5);
29-
console.log("RPC:", out);
30-
31-
await new Promise((resolve) => setTimeout(resolve, 1000));
32-
}
33-
34-
await new Promise((resolve) => setTimeout(resolve, 2000));
35-
await counter2.dispose();
10+
await counter.increment(1);
11+
12+
setInterval(() => {}, 1000);
13+
14+
// for (let i = 0; i < 5; i++) {
15+
// const out = await counter.increment(5);
16+
// console.log("RPC:", out);
17+
//
18+
// await new Promise((resolve) => setTimeout(resolve, 1000));
19+
// }
20+
//
21+
// await new Promise((resolve) => setTimeout(resolve, 2000));
22+
// await counter.dispose();
23+
//
24+
// await new Promise((resolve) => setTimeout(resolve, 200));
25+
//
26+
// const counter2 = client.counter.getOrCreate().connect();
27+
//
28+
// counter2.on("newCount", (count: number) => console.log("Event:", count));
29+
//
30+
// for (let i = 0; i < 5; i++) {
31+
// const out = await counter2.increment(5);
32+
// console.log("RPC:", out);
33+
//
34+
// await new Promise((resolve) => setTimeout(resolve, 1000));
35+
// }
36+
//
37+
// await new Promise((resolve) => setTimeout(resolve, 2000));
38+
// await counter2.dispose();
3639
}
3740

3841
main();

examples/smoke-test/src/smoke-test/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ function logProgress({
6666
startedCount - (successCount + failureCount),
6767
);
6868
console.log(
69-
`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)}`,
69+
`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)}`,
7070
);
7171
}
7272

7373
async function main() {
74-
const client = createClient<Registry>("http://localhost:6420");
74+
const client = createClient<Registry>();
7575
const testId = randomUUID();
7676
const errors: SmokeTestError[] = [];
7777
let successCount = 0;
@@ -130,7 +130,7 @@ async function main() {
130130

131131
const finalStats = calculateDurationStats(iterationDurations);
132132
console.log(
133-
`iteration duration stats (ms): avg=${finalStats.average.toFixed(2)}, median=${finalStats.median.toFixed(2)}, min=${finalStats.min.toFixed(2)}, max=${finalStats.max.toFixed(2)}`,
133+
`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)}`,
134134
);
135135

136136
if (errors.length > 0) {

examples/smoke-test/src/smoke-test/spawn-actor.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,33 @@ export async function spawnActor({
2828
onSuccess,
2929
onFailure,
3030
}: SpawnActorOptions): Promise<void> {
31-
const iterationStart = performance.now();
3231
let succeeded = false;
3332

3433
try {
35-
const key = ["test", testId, index.toString()];
36-
const counter = client.counter.getOrCreate(key).connect();
37-
await counter.increment(1);
38-
await counter.dispose();
34+
for (let i = 0; i < 20; i++) {
35+
// Connect to actor
36+
const connMethod = Math.random() > 0.5 ? "http" : "websocket";
37+
const iterationStart = performance.now();
38+
if (connMethod === "websocket") {
39+
const key = ["test", testId, index.toString()];
40+
const counter = client.counter.getOrCreate(key).connect();
41+
await counter.increment(1);
42+
await counter.dispose();
43+
} else if (connMethod === "http") {
44+
const key = ["test", testId, index.toString()];
45+
const counter = client.counter.getOrCreate(key);
46+
await counter.increment(1);
47+
}
48+
const iterationEnd = performance.now();
49+
const iterationDuration = iterationEnd - iterationStart;
50+
iterationDurations.push(iterationDuration);
3951

40-
// Immediately reconnect
41-
const counter2 = client.counter.getOrCreate(key).connect();
42-
await counter2.increment(1);
43-
await counter2.dispose();
44-
45-
// Wait for actor to sleep
46-
await new Promise((res) => setTimeout(res, 1000));
47-
48-
// Reconnect after sleep
49-
const counter3 = client.counter.getOrCreate(key).connect();
50-
await counter3.increment(1);
51-
await counter3.dispose();
52+
// Wait for actor to sleep (if > 500 ms)
53+
const sleepTime = 100 + Math.random() * 800;
54+
console.log("sleeping", sleepTime);
55+
// const sleepTime = 1000;
56+
await new Promise((res) => setTimeout(res, sleepTime));
57+
}
5258

5359
succeeded = true;
5460
onSuccess();
@@ -58,8 +64,5 @@ export async function spawnActor({
5864
}
5965

6066
if (succeeded) {
61-
const iterationEnd = performance.now();
62-
const iterationDuration = iterationEnd - iterationStart;
63-
iterationDurations.push(iterationDuration);
6467
}
6568
}

0 commit comments

Comments
 (0)