-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
335 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,15 @@ | ||
use axum::{extract::State, routing::post, Router}; | ||
|
||
use crate::{interfaces::HostResult, ProverState}; | ||
use crate::interfaces::HostResult; | ||
use raiko_reqactor::Gateway; | ||
|
||
pub fn create_router() -> Router<ProverState> { | ||
Router::new() | ||
.route("/admin/pause", post(pause)) | ||
.route("/admin/unpause", post(unpause)) | ||
pub fn create_router<P: raiko_reqpool::Pool + 'static>() -> Router<Gateway<P>> { | ||
Router::new().route("/admin/pause", post(pause)) | ||
} | ||
|
||
async fn pause(State(state): State<ProverState>) -> HostResult<&'static str> { | ||
state.set_pause(true).await?; | ||
async fn pause<P: raiko_reqpool::Pool>( | ||
State(gateway): State<Gateway<P>>, | ||
) -> HostResult<&'static str> { | ||
gateway.pause().await.map_err(|e| anyhow::anyhow!(e))?; | ||
Ok("System paused successfully") | ||
} | ||
|
||
async fn unpause(State(state): State<ProverState>) -> HostResult<&'static str> { | ||
state.set_pause(false).await?; | ||
Ok("System unpaused successfully") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use axum::{ | ||
body::Body, | ||
http::{Request, StatusCode}, | ||
}; | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
use tower::ServiceExt; | ||
|
||
#[tokio::test] | ||
async fn test_pause() { | ||
let opts = { | ||
let mut opts = crate::Opts::parse(); | ||
opts.config_path = PathBuf::from("../host/config/config.json"); | ||
opts.merge_from_file().unwrap(); | ||
opts | ||
}; | ||
let state = ProverState::init_with_opts(opts).unwrap(); | ||
let app = Router::new() | ||
.route("/admin/pause", post(pause)) | ||
.with_state(state.clone()); | ||
|
||
let request = Request::builder() | ||
.method("POST") | ||
.uri("/admin/pause") | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let response = app.oneshot(request).await.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert!(state.is_paused()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_pause_when_already_paused() { | ||
let opts = { | ||
let mut opts = crate::Opts::parse(); | ||
opts.config_path = PathBuf::from("../host/config/config.json"); | ||
opts.merge_from_file().unwrap(); | ||
opts | ||
}; | ||
let state = ProverState::init_with_opts(opts).unwrap(); | ||
|
||
state.set_pause(true).await.unwrap(); | ||
|
||
let app = Router::new() | ||
.route("/admin/pause", post(pause)) | ||
.with_state(state.clone()); | ||
|
||
let request = Request::builder() | ||
.method("POST") | ||
.uri("/admin/pause") | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let response = app.oneshot(request).await.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert!(state.is_paused()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_unpause() { | ||
let opts = { | ||
let mut opts = crate::Opts::parse(); | ||
opts.config_path = PathBuf::from("../host/config/config.json"); | ||
opts.merge_from_file().unwrap(); | ||
opts | ||
}; | ||
let state = ProverState::init_with_opts(opts).unwrap(); | ||
|
||
// Set initial paused state | ||
state.set_pause(true).await.unwrap(); | ||
assert!(state.is_paused()); | ||
|
||
let app = Router::new() | ||
.route("/admin/unpause", post(unpause)) | ||
.with_state(state.clone()); | ||
|
||
let request = Request::builder() | ||
.method("POST") | ||
.uri("/admin/unpause") | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let response = app.oneshot(request).await.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert!(!state.is_paused()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.