Skip to content

Commit f3ae818

Browse files
committed
chore: fix tests (#3093)
1 parent 9b7e5ec commit f3ae818

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

packages/core/guard/core/src/proxy_service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,9 @@ fn err_into_response(err: anyhow::Error) -> Result<Response<ResponseBody>> {
22532253
let (status, error_response) =
22542254
if let Some(rivet_err) = err.chain().find_map(|x| x.downcast_ref::<RivetError>()) {
22552255
let status = match (rivet_err.group(), rivet_err.code()) {
2256+
("api", "not_found") => StatusCode::NOT_FOUND,
2257+
("api", "unauthorized") => StatusCode::UNAUTHORIZED,
2258+
("api", "forbidden") => StatusCode::FORBIDDEN,
22562259
("guard", "rate_limit") => StatusCode::TOO_MANY_REQUESTS,
22572260
("guard", "upstream_error") => StatusCode::BAD_GATEWAY,
22582261
("guard", "routing_error") => StatusCode::BAD_GATEWAY,

packages/core/pegboard-serverless/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::{
22
collections::HashMap,
33
sync::{
4-
atomic::{AtomicBool, Ordering},
54
Arc,
5+
atomic::{AtomicBool, Ordering},
66
},
77
};
88

99
use anyhow::Result;
10-
use base64::engine::general_purpose::STANDARD as BASE64;
1110
use base64::Engine;
11+
use base64::engine::general_purpose::STANDARD as BASE64;
1212
use futures_util::{StreamExt, TryStreamExt};
1313
use gas::prelude::*;
1414
use pegboard::keys;

packages/services/epoxy/src/ops/propose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub async fn run_paxos_accept(
121121
}
122122

123123
#[tracing::instrument(skip_all)]
124-
pub async fn commit(
124+
async fn commit(
125125
ctx: &OperationCtx,
126126
config: &protocol::ClusterConfig,
127127
replica_id: ReplicaId,

scripts/tests/actor_e2e.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
#!/usr/bin/env tsx
22

3-
import { RIVET_ENDPOINT, RIVET_TOKEN, createActor, destroyActor } from "./utils";
3+
import { RIVET_ENDPOINT, RIVET_TOKEN, RIVET_NAMESPACE, createActor, destroyActor } from "./utils";
44

55
async function main() {
6+
let actorId;
7+
68
try {
79
console.log("Starting actor E2E test...");
810

911
// Create an actor
1012
console.log("Creating actor...");
11-
const actorResponse = await createActor("default", "test-runner");
13+
const actorResponse = await createActor(RIVET_NAMESPACE, "test-runner");
1214
console.log("Actor created:", actorResponse.actor);
1315

16+
actorId = actorResponse.actor.actor_id;
17+
1418
// Make a request to the actor
1519
console.log("Making request to actor...");
1620
const actorPingResponse = await fetch(`${RIVET_ENDPOINT}/ping`, {
1721
method: "GET",
1822
headers: {
23+
"X-Rivet-Token": RIVET_TOKEN,
1924
"X-Rivet-Target": "actor",
2025
"X-Rivet-Actor": actorResponse.actor.actor_id,
2126
},
@@ -32,17 +37,13 @@ async function main() {
3237
console.log("Actor ping response:", pingResult);
3338

3439
await testWebSocket(actorResponse.actor.actor_id);
35-
36-
console.log("Destroying actor...");
37-
await destroyActor("default", actorResponse.actor.actor_id);
38-
39-
console.log("E2E test completed successfully!");
40-
41-
// HACK: This script does not exit by itself for some reason
42-
process.exit(0);
4340
} catch (error) {
44-
console.error("E2E test failed:", error);
45-
process.exit(1);
41+
console.error(`Actor ${i} test failed:`, error);
42+
} finally {
43+
if (actorId) {
44+
console.log(`Destroying actor ${i}...`);
45+
await destroyActor(RIVET_NAMESPACE, actorId);
46+
}
4647
}
4748
}
4849

scripts/tests/spam_actors.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env tsx
22

3-
import { RIVET_ENDPOINT, RIVET_TOKEN, createActor, destroyActor } from "./utils";
3+
import { RIVET_ENDPOINT, RIVET_TOKEN, RIVET_NAMESPACE, createActor, destroyActor } from "./utils";
44

55
const ACTORS = parseInt(process.argv[2]) || 15;
66

@@ -18,17 +18,21 @@ async function main() {
1818
}
1919

2020
async function testActor(i: number) {
21+
let actorId;
2122
try {
2223
// Create an actor
2324
console.log(`Creating actor ${i}...`);
24-
const actorResponse = await createActor("default", "test-runner");
25+
const actorResponse = await createActor(RIVET_NAMESPACE, "test-runner");
2526
console.log("Actor created:", actorResponse.actor);
2627

28+
actorId = actorResponse.actor.actor_id;
29+
2730
// Make a request to the actor
2831
console.log(`Making request to actor ${i}...`);
2932
const actorPingResponse = await fetch(`${RIVET_ENDPOINT}/ping`, {
3033
method: "GET",
3134
headers: {
35+
"X-Rivet-Token": RIVET_TOKEN,
3236
"X-Rivet-Target": "actor",
3337
"X-Rivet-Actor": actorResponse.actor.actor_id,
3438
},
@@ -45,11 +49,13 @@ async function testActor(i: number) {
4549
console.log(`Actor ${i} ping response:`, pingResult);
4650

4751
await testWebSocket(actorResponse.actor.actor_id);
48-
49-
console.log(`Destroying actor ${i}...`);
50-
await destroyActor("default", actorResponse.actor.actor_id);
5152
} catch (error) {
5253
console.error(`Actor ${i} test failed:`, error);
54+
} finally {
55+
if (actorId) {
56+
console.log(`Destroying actor ${i}...`);
57+
await destroyActor(RIVET_NAMESPACE, actorId);
58+
}
5359
}
5460
}
5561

scripts/tests/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const RIVET_ENDPOINT =
22
process.env.RIVET_ENDPOINT ?? "http://localhost:6420";
33
export const RIVET_TOKEN = process.env.RIVET_TOKEN ?? "dev";
4+
export const RIVET_NAMESPACE = process.env.RIVET_NAMESPACE ?? "default";
45

56
export async function createActor(
67
namespaceName: string,
@@ -11,6 +12,7 @@ export async function createActor(
1112
{
1213
method: "POST",
1314
headers: {
15+
"Authorization": `Bearer ${RIVET_TOKEN}`,
1416
"Content-Type": "application/json",
1517
},
1618
body: JSON.stringify({
@@ -64,6 +66,7 @@ export async function getOrCreateActorById(
6466
{
6567
method: "PUT",
6668
headers: {
69+
"Authorization": `Bearer ${RIVET_TOKEN}`,
6770
"Content-Type": "application/json",
6871
},
6972
body: JSON.stringify({
@@ -95,6 +98,9 @@ export async function listActors(
9598

9699
const response = await fetch(url, {
97100
method: "GET",
101+
headers: {
102+
"Authorization": `Bearer ${RIVET_TOKEN}`,
103+
}
98104
});
99105

100106
if (!response.ok) {

0 commit comments

Comments
 (0)