Skip to content

Commit 4aa8775

Browse files
committed
chore: cleanup rivet-engine tests
1 parent cc6695a commit 4aa8775

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+8379
-3840
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/packages/api-peer/src/actors/delete.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
use anyhow::Result;
22
use gas::prelude::*;
33
use rivet_api_builder::ApiCtx;
4+
use rivet_api_types::actors::delete::*;
45
use rivet_util::Id;
5-
use serde::{Deserialize, Serialize};
6-
use utoipa::{IntoParams, ToSchema};
7-
8-
#[derive(Debug, Deserialize, Serialize, IntoParams)]
9-
#[serde(deny_unknown_fields)]
10-
#[into_params(parameter_in = Query)]
11-
pub struct DeleteQuery {
12-
pub namespace: Option<String>,
13-
}
14-
15-
#[derive(Serialize, ToSchema)]
16-
#[schema(as = ActorsDeleteResponse)]
17-
pub struct DeleteResponse {}
18-
19-
#[derive(Deserialize)]
20-
#[serde(deny_unknown_fields)]
21-
pub struct DeletePath {
22-
pub actor_id: Id,
23-
}
246

257
#[utoipa::path(
268
delete,

engine/packages/api-peer/src/internal.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct CachePurgeRequest {
1010
pub keys: Vec<rivet_cache::RawCacheKey>,
1111
}
1212

13-
#[derive(Serialize)]
13+
#[derive(Serialize, Deserialize)]
1414
#[serde(deny_unknown_fields)]
1515
pub struct CachePurgeResponse {}
1616

@@ -29,7 +29,7 @@ pub async fn cache_purge(
2929
Ok(CachePurgeResponse {})
3030
}
3131

32-
#[derive(Serialize)]
32+
#[derive(Serialize, Deserialize)]
3333
#[serde(deny_unknown_fields)]
3434
pub struct BumpServerlessAutoscalerResponse {}
3535

@@ -55,7 +55,7 @@ pub struct SetTracingConfigRequest {
5555
pub sampler_ratio: Option<Option<f64>>,
5656
}
5757

58-
#[derive(Serialize)]
58+
#[derive(Serialize, Deserialize)]
5959
#[serde(deny_unknown_fields)]
6060
pub struct SetTracingConfigResponse {}
6161

@@ -83,11 +83,11 @@ pub async fn set_tracing_config(
8383
Ok(SetTracingConfigResponse {})
8484
}
8585

86-
#[derive(Deserialize)]
86+
#[derive(Serialize, Deserialize)]
8787
#[serde(deny_unknown_fields)]
8888
pub struct ReplicaReconfigureRequest {}
8989

90-
#[derive(Serialize)]
90+
#[derive(Serialize, Deserialize)]
9191
#[serde(deny_unknown_fields)]
9292
pub struct ReplicaReconfigureResponse {}
9393

@@ -114,7 +114,7 @@ pub async fn epoxy_replica_reconfigure(
114114
Ok(ReplicaReconfigureResponse {})
115115
}
116116

117-
#[derive(Serialize)]
117+
#[derive(Serialize, Deserialize)]
118118
#[serde(deny_unknown_fields)]
119119
pub struct GetEpoxyStateResponse {
120120
pub config: epoxy::types::ClusterConfig,
@@ -143,13 +143,13 @@ pub async fn get_epoxy_state(ctx: ApiCtx, _path: (), _query: ()) -> Result<GetEp
143143
})
144144
}
145145

146-
#[derive(Deserialize)]
146+
#[derive(Serialize, Deserialize)]
147147
#[serde(deny_unknown_fields)]
148148
pub struct SetEpoxyStateRequest {
149149
pub config: epoxy::types::ClusterConfig,
150150
}
151151

152-
#[derive(Serialize)]
152+
#[derive(Serialize, Deserialize)]
153153
#[serde(deny_unknown_fields)]
154154
pub struct SetEpoxyStateResponse {}
155155

engine/packages/api-peer/src/namespaces.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result<ListRespon
6262
#[serde(deny_unknown_fields)]
6363
#[schema(as = NamespacesCreateRequest)]
6464
pub struct CreateRequest {
65-
name: String,
66-
display_name: String,
65+
pub name: String,
66+
pub display_name: String,
6767
}
6868

6969
#[derive(Serialize, Deserialize, ToSchema)]

engine/packages/api-peer/src/runners.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use anyhow::Result;
22
use rivet_api_builder::ApiCtx;
3-
use rivet_api_types::{pagination::Pagination, runners::list::*};
4-
use serde::{Deserialize, Serialize};
5-
use utoipa::{IntoParams, ToSchema};
3+
use rivet_api_types::{pagination::Pagination, runners::list::*, runners::list_names::*};
64

75
#[utoipa::path(
86
get,
@@ -60,23 +58,6 @@ pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result<ListRespon
6058
}
6159
}
6260

63-
#[derive(Debug, Serialize, Deserialize, Clone, IntoParams)]
64-
#[serde(deny_unknown_fields)]
65-
#[into_params(parameter_in = Query)]
66-
pub struct ListNamesQuery {
67-
pub namespace: String,
68-
pub limit: Option<usize>,
69-
pub cursor: Option<String>,
70-
}
71-
72-
#[derive(Serialize, Deserialize, ToSchema)]
73-
#[serde(deny_unknown_fields)]
74-
#[schema(as = RunnersListNamesResponse)]
75-
pub struct ListNamesResponse {
76-
pub names: Vec<String>,
77-
pub pagination: Pagination,
78-
}
79-
8061
#[tracing::instrument(skip_all)]
8162
pub async fn list_names(
8263
ctx: ApiCtx,

engine/packages/api-public/src/actors/create.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,11 @@ use rivet_api_builder::{
44
ApiError,
55
extract::{Extension, Json, Query},
66
};
7-
use rivet_api_types::actors::create::{CreateRequest, CreateResponse};
7+
use rivet_api_types::actors::create::*;
88
use rivet_api_util::request_remote_datacenter;
9-
use serde::{Deserialize, Serialize};
10-
use utoipa::IntoParams;
119

1210
use crate::ctx::ApiCtx;
1311

14-
#[derive(Debug, Serialize, Deserialize, IntoParams)]
15-
#[serde(deny_unknown_fields)]
16-
#[into_params(parameter_in = Query)]
17-
pub struct CreateQuery {
18-
pub namespace: String,
19-
}
20-
2112
/// ## Datacenter Round Trips
2213
///
2314
/// **If actor is created in the current datacenter:**

engine/packages/api-public/src/actors/delete.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@ use rivet_api_builder::{
44
ApiError,
55
extract::{Extension, Json, Path, Query},
66
};
7+
use rivet_api_types::actors::delete::*;
78
use rivet_api_util::request_remote_datacenter_raw;
89
use rivet_util::Id;
9-
use serde::{Deserialize, Serialize};
10-
use utoipa::{IntoParams, ToSchema};
1110

1211
use crate::ctx::ApiCtx;
1312

14-
#[derive(Debug, Deserialize, Serialize, IntoParams)]
15-
#[serde(deny_unknown_fields)]
16-
#[into_params(parameter_in = Query)]
17-
pub struct DeleteQuery {
18-
pub namespace: Option<String>,
19-
}
20-
21-
#[derive(Deserialize)]
22-
#[serde(deny_unknown_fields)]
23-
pub struct DeletePath {
24-
pub actor_id: Id,
25-
}
26-
27-
#[derive(Serialize, ToSchema)]
28-
#[schema(as = ActorsDeleteResponse)]
29-
pub struct DeleteResponse {}
30-
3113
/// ## Datacenter Round Trips
3214
///
3315
/// 2 round trip:
@@ -63,13 +45,7 @@ async fn delete_inner(ctx: ApiCtx, path: DeletePath, query: DeleteQuery) -> Resu
6345
ctx.auth().await?;
6446

6547
if path.actor_id.label() == ctx.config().dc_label() {
66-
let peer_path = rivet_api_peer::actors::delete::DeletePath {
67-
actor_id: path.actor_id,
68-
};
69-
let peer_query = rivet_api_peer::actors::delete::DeleteQuery {
70-
namespace: query.namespace,
71-
};
72-
let res = rivet_api_peer::actors::delete::delete(ctx.into(), peer_path, peer_query).await?;
48+
let res = rivet_api_peer::actors::delete::delete(ctx.into(), path, query).await?;
7349

7450
Ok(Json(res).into_response())
7551
} else {

engine/packages/api-public/src/actors/list.rs

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,11 @@ use rivet_api_builder::{
44
ApiError,
55
extract::{Extension, Json, Query},
66
};
7-
use rivet_api_types::pagination::Pagination;
7+
use rivet_api_types::{actors::list::*, pagination::Pagination};
88
use rivet_api_util::fanout_to_datacenters;
9-
use serde::{Deserialize, Serialize};
10-
use utoipa::{IntoParams, ToSchema};
119

1210
use crate::{actors::utils::fetch_actors_by_ids, ctx::ApiCtx, errors};
1311

14-
#[derive(Debug, Serialize, Deserialize, Clone, IntoParams)]
15-
#[serde(deny_unknown_fields)]
16-
#[into_params(parameter_in = Query)]
17-
pub struct ListQuery {
18-
pub namespace: String,
19-
pub name: Option<String>,
20-
pub key: Option<String>,
21-
pub actor_ids: Option<String>,
22-
pub include_destroyed: Option<bool>,
23-
pub limit: Option<usize>,
24-
pub cursor: Option<String>,
25-
}
26-
27-
#[derive(Serialize, Deserialize, ToSchema)]
28-
#[serde(deny_unknown_fields)]
29-
#[schema(as = ActorsListResponse)]
30-
pub struct ListResponse {
31-
pub actors: Vec<rivet_types::actors::Actor>,
32-
pub pagination: Pagination,
33-
}
34-
3512
/// ## Datacenter Round Trips
3613
///
3714
/// **If key is some & `include_destroyed` is false**
@@ -123,15 +100,25 @@ async fn list_inner(ctx: ApiCtx, query: ListQuery) -> Result<ListResponse> {
123100
.ok_or_else(|| namespace::errors::Namespace::NotFound.build())?;
124101

125102
// Fetch actors
126-
let actors = fetch_actors_by_ids(
103+
let mut actors = fetch_actors_by_ids(
127104
&ctx,
128105
actor_ids,
129106
query.namespace.clone(),
130107
query.include_destroyed,
131-
query.limit,
108+
None, // Don't apply limit in fetch, we'll apply it after cursor filtering
132109
)
133110
.await?;
134111

112+
// Apply cursor filtering if provided
113+
if let Some(cursor_str) = &query.cursor {
114+
let cursor_ts: i64 = cursor_str.parse().context("invalid cursor format")?;
115+
actors.retain(|actor| actor.create_ts < cursor_ts);
116+
}
117+
118+
// Apply limit after cursor filtering
119+
let limit = query.limit.unwrap_or(100);
120+
actors.truncate(limit);
121+
135122
let cursor = actors.last().map(|x| x.create_ts.to_string());
136123

137124
Ok(ListResponse {
@@ -196,40 +183,25 @@ async fn list_inner(ctx: ApiCtx, query: ListQuery) -> Result<ListResponse> {
196183
.build());
197184
}
198185

199-
// Prepare peer query for local handler
200-
let peer_query = rivet_api_types::actors::list::ListQuery {
201-
namespace: query.namespace.clone(),
202-
name: Some(query.name.as_ref().unwrap().clone()),
203-
key: query.key.clone(),
204-
actor_ids: None,
205-
include_destroyed: query.include_destroyed,
206-
limit: query.limit,
207-
cursor: query.cursor.clone(),
208-
};
186+
let limit = query.limit.unwrap_or(100);
209187

210188
// Fanout to all datacenters
211-
let mut actors = fanout_to_datacenters::<
212-
rivet_api_types::actors::list::ListResponse,
213-
_,
214-
_,
215-
_,
216-
_,
217-
Vec<rivet_types::actors::Actor>,
218-
>(
219-
ctx.into(),
220-
"/actors",
221-
peer_query,
222-
|ctx, query| async move { rivet_api_peer::actors::list::list(ctx, (), query).await },
223-
|_, res, agg| agg.extend(res.actors),
224-
)
225-
.await?;
189+
let mut actors =
190+
fanout_to_datacenters::<ListResponse, _, _, _, _, Vec<rivet_types::actors::Actor>>(
191+
ctx.into(),
192+
"/actors",
193+
query,
194+
|ctx, query| async move { rivet_api_peer::actors::list::list(ctx, (), query).await },
195+
|_, res, agg| agg.extend(res.actors),
196+
)
197+
.await?;
226198

227199
// Sort by create ts desc
228200
actors.sort_by_cached_key(|x| std::cmp::Reverse(x.create_ts));
229201

230202
// Shorten array since returning all actors from all regions could end up returning `regions *
231203
// limit` results, which is a lot.
232-
actors.truncate(query.limit.unwrap_or(100));
204+
actors.truncate(limit);
233205

234206
let cursor = actors.last().map(|x| x.create_ts.to_string());
235207

0 commit comments

Comments
 (0)