Skip to content

Commit

Permalink
ci(CI): 🧱 add master cargo test ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jan 3, 2024
1 parent 9561529 commit 4cff94d
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 275 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
env:
CARGO_TERM_COLOR: always


jobs:
check:
name: Check
Expand Down Expand Up @@ -44,3 +45,5 @@ jobs:
with:
command: fmt
args: --manifest-path ./backend/Cargo.toml


51 changes: 51 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: master

on:
push:
branches:
- "*"
paths:
- "**.rs"
- .github/workflows/master.yml

env:
CARGO_TERM_COLOR: always

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-x86_64-unknown-linux-gnu
override: true
components: rustfmt, clippy
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Lint
run: |
cargo fmt --all -- --check
cargo clippy -- -D warnings
- name: Check
run: cargo check
- name: Run Backend Test
run: cargo test -p backend
- name: Run Frontend Test
run: cargo test -p frontend
# judger need to build plugin first(which take long time)
# - name: Run Judger test
# run: cd judger && just test
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/cert.pem
/a.log
/judger.proto
/backend.proto
/backend.proto
/ws-Cargo.toml
6 changes: 0 additions & 6 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,3 @@ features = ["mutex", "spin_mutex", "rwlock"]

[build-dependencies]
tonic-build = { workspace = true }

[features]
default = ["single-instance"]
unsecured-log = []
single-instance = []
testsuit = []
3 changes: 3 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ WORKDIR /complier/proto
COPY backend.proto .
COPY judger.proto .

WORKDIR /compiler
COPY ws-Cargo.toml Cargo.toml

WORKDIR /complier/backend
COPY . .

Expand Down
18 changes: 16 additions & 2 deletions backend/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("../proto/backend.proto")?;
tonic_build::compile_protos("../proto/judger.proto")?;
tonic_build::configure()
.build_client(false)
.type_attribute(
"oj.backend.SortBy",
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.compile(&["../proto/backend.proto"], &["../proto"])?;
// tonic_build::compile_protos("../proto/backend.proto")?;
// tonic_build::compile_protos("../proto/judger.proto")?;
tonic_build::configure()
.build_server(false)
.type_attribute(
"oj.backend.SortBy",
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.compile(&["../proto/judger.proto"], &["../proto"])?;
Ok(())
}
8 changes: 0 additions & 8 deletions backend/src/controller/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,32 @@ use tracing::Span;
use uuid::Uuid;

pub struct DupController {
#[cfg(feature = "single-instance")]
dup_i32: Cache<(i32, Uuid), i32>,
#[cfg(feature = "single-instance")]
dup_str: Cache<(i32, Uuid), String>,
}

impl DupController {
#[tracing::instrument(parent=span, name="duplicate_construct",level = "info",skip_all)]
pub fn new(span: &Span) -> Self {
Self {
#[cfg(feature = "single-instance")]
dup_i32: Cache::new(150),
#[cfg(feature = "single-instance")]
dup_str: Cache::new(150),
}
}
/// store a request_id with result i32
pub fn store_i32(&self, spliter: i32, uuid: Uuid, result: i32) {
tracing::trace!(request_id=?uuid);
#[cfg(feature = "single-instance")]
self.dup_i32.insert((spliter, uuid), result);
}
/// store a request_id with result String
pub fn store_str(&self, spliter: i32, uuid: Uuid, result: String) {
tracing::trace!(request_id=?uuid);
#[cfg(feature = "single-instance")]
self.dup_str.insert((spliter, uuid), result);
}
/// attempt to get result of i32
#[tracing::instrument(level = "debug", skip(self))]
pub fn check_i32(&self, spliter: i32, uuid: &Uuid) -> Option<i32> {
tracing::trace!(request_id=?uuid);
#[cfg(feature = "single-instance")]
if let Some(x) = self.dup_i32.get(&(spliter, *uuid)) {
log::debug!("duplicated request_id: {}, result: {}", uuid, x);
return Some(x);
Expand All @@ -46,7 +39,6 @@ impl DupController {
#[tracing::instrument(level = "debug", skip(self))]
pub fn check_str(&self, spliter: i32, uuid: &Uuid) -> Option<String> {
tracing::trace!(request_id=?uuid);
#[cfg(feature = "single-instance")]
if let Some(x) = self.dup_str.get(&(spliter, *uuid)) {
log::debug!("duplicated request_id: {}, result: {}", uuid, x);
return Some(x);
Expand Down
8 changes: 0 additions & 8 deletions backend/src/controller/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl From<token::Model> for CachedToken {
}

pub struct TokenController {
#[cfg(feature = "single-instance")]
cache: Cache<Rand, CachedToken>,
rng: Mutex<Hc128Rng>,
cache_meter: RateMetrics<30>,
Expand All @@ -72,10 +71,8 @@ impl TokenController {
#[tracing::instrument(parent = span,name="token_construct_controller",level = "info",skip_all)]
pub fn new(span: &Span) -> Arc<Self> {
log::debug!("Setup TokenController");
#[cfg(feature = "single-instance")]
let cache = Cache::new(500);
let self_ = Arc::new(Self {
#[cfg(feature = "single-instance")]
cache,
rng: Mutex::new(Hc128Rng::from_entropy()),
cache_meter: RateMetrics::new("hitrate_token"),
Expand Down Expand Up @@ -137,7 +134,6 @@ impl TokenController {

let token: CachedToken;

#[cfg(feature = "single-instance")]
let cache_result = {
match self.cache.get(&rand) {
Some(cc) => {
Expand All @@ -151,8 +147,6 @@ impl TokenController {
None => None,
}
};
#[cfg(not(feature = "single-instance"))]
let cache_result: Option<CachedToken> = None;

let token = match cache_result {
Some(token) => {
Expand All @@ -172,7 +166,6 @@ impl TokenController {
tracing::trace!(user_id = token.user_id, "cache_missed");
self.cache_meter.unset();

#[cfg(feature = "single-instance")]
self.cache.insert(rand, token.clone());

token
Expand All @@ -199,7 +192,6 @@ impl TokenController {
.exec(db)
.await?;

#[cfg(feature = "single-instance")]
self.cache.remove(&rand);

Ok(Some(()))
Expand Down
14 changes: 7 additions & 7 deletions backend/src/endpoint/util/pager/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PagerTrait for problem::Entity {
_ => problem::Column::Id,
}
}
fn get_key_of(model: &Self::Model, sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, sort: &SortBy) -> String {
match sort {
SortBy::UploadDate => model.update_at.to_string(),
SortBy::CreateDate => model.create_at.to_string(),
Expand Down Expand Up @@ -90,7 +90,7 @@ impl PagerTrait for test::Entity {
_ => test::Column::Id,
}
}
fn get_key_of(model: &Self::Model, sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, sort: &SortBy) -> String {
match sort {
SortBy::Score => (model.score).to_string(),
_ => model.id.to_string(),
Expand Down Expand Up @@ -128,7 +128,7 @@ impl PagerTrait for contest::Entity {
_ => contest::Column::Id,
}
}
fn get_key_of(model: &Self::Model, sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, sort: &SortBy) -> String {
match sort {
SortBy::CreateDate => model.create_at.to_string(),
SortBy::UploadDate => model.update_at.to_string(),
Expand Down Expand Up @@ -170,7 +170,7 @@ impl PagerTrait for user::Entity {
_ => user::Column::Id,
}
}
fn get_key_of(model: &Self::Model, sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, sort: &SortBy) -> String {
match sort {
SortBy::CreateDate => model.create_at.to_string(),
SortBy::Score => model.score.to_string(),
Expand Down Expand Up @@ -215,7 +215,7 @@ impl PagerTrait for submit::Entity {
_ => submit::Column::Id,
}
}
fn get_key_of(model: &Self::Model, sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, sort: &SortBy) -> String {
match sort {
SortBy::Committed => match model.committed {
true => "1".to_string(),
Expand Down Expand Up @@ -253,7 +253,7 @@ impl PagerTrait for education::Entity {
fn sort_column(_sort: &SortBy) -> education::Column {
education::Column::Id
}
fn get_key_of(model: &Self::Model, _sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, _sort: &SortBy) -> String {
model.id.to_string()
}
fn get_id(model: &Self::Model) -> i32 {
Expand All @@ -276,7 +276,7 @@ impl PagerTrait for chat::Entity {

type ParentMarker = HasParent<problem::Entity>;

fn get_key_of(model: &Self::Model, _sort: &SortBy) -> String {
fn sort_value(model: &Self::Model, _sort: &SortBy) -> String {
model.id.to_string()
}

Expand Down
Loading

0 comments on commit 4cff94d

Please sign in to comment.