Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(実験用)並列テスト #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ on:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
CARGO_PROFILE_TEST_DEBUG: 0
SQL_URL: postgres://db_user:db_pass@localhost:5432/test_db
DATABASE_URL: postgres://db_user:db_pass@localhost:5432/test_db

jobs:
backend_test:
Expand Down Expand Up @@ -44,8 +43,9 @@ jobs:
with:
workspaces: atcoder-problems-backend -> target

# ここは無くてもいいかも
- name: Setup Postgresql
run: psql ${SQL_URL} < ../config/database-definition.sql
run: psql ${DATABASE_URL} < ../config/database-definition.sql

- name: Setup
run: rustup component add rustfmt
Expand All @@ -60,7 +60,7 @@ jobs:
run: cargo test --no-run --workspace --locked --verbose

- name: Run tests
run: cargo test --workspace --locked --verbose -- --test-threads=1
run: cargo test --workspace --locked --verbose

frontend_test:
name: Run frontend tests
Expand Down
1 change: 1 addition & 0 deletions atcoder-problems-backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions atcoder-problems-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ futures-util = "0.3.25"

[dev-dependencies]
httpmock = "0.6.6"
sqlx = { version = "0.6.2", features = ["postgres", "runtime-tokio-rustls"] }

[workspace]
members = ["sql-client", "atcoder-client"]
4 changes: 2 additions & 2 deletions atcoder-problems-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker-compose exec backend-development cargo build
## Run

```bash
export SQL_URL=... # Connection URL of PostgreSQL
export DATABASE_URL=... # Connection URL of PostgreSQL
export CLIENT_ID=... # GitHub client_id, which is required to use the login function.
export CLIENT_SECRET=... # GitHub client_secret, which is required to use the login function.

Expand All @@ -71,7 +71,7 @@ cargo run --bin fix_invalid_submissions

```bash
docker-compose up -d
docker-compose exec backend-development cargo test --workspace -- --test-threads=1
docker-compose exec backend-development cargo test --workspace
```

## Format
Expand Down
2 changes: 1 addition & 1 deletion atcoder-problems-backend/scripts/sql-backup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

psql ${SQL_URL} -c "\copy submissions TO './submissions.csv' WITH (FORMAT CSV, HEADER)"
psql ${DATABASE_URL} -c "\copy submissions TO './submissions.csv' WITH (FORMAT CSV, HEADER)"
gzip submissions.csv
aws s3 cp submissions.csv.gz s3://kenkoooo/submissions.csv.gz --acl public-read
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use sql_client::accepted_count::AcceptedCountClient;
use sql_client::models::{Submission, UserProblemCount};
use sql_client::PgPool;

mod utils;

#[tokio::test]
async fn test_accepted_count() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_accepted_count(pool: PgPool) {
utils::initialize(&pool).await;

let submissions = [
Submission {
id: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use sql_client::contest_problem::ContestProblemClient;
use sql_client::models::ContestProblem;
use sql_client::PgPool;

mod utils;

Expand All @@ -11,9 +12,10 @@ fn create_problem(id: i32) -> ContestProblem {
}
}

#[tokio::test]
async fn test_contest_problem() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_contest_problem(pool: PgPool) {
utils::initialize(&pool).await;

assert!(pool.load_contest_problem().await.unwrap().is_empty());

pool.insert_contest_problem(&[create_problem(1), create_problem(2)])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use sql_client::language_count::LanguageCountClient;
use sql_client::models::{Submission, UserLanguageCount, UserLanguageCountRank, UserProblemCount};
use sql_client::PgPool;

mod utils;

#[tokio::test]
async fn test_language_count() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_language_count(pool: PgPool) {
utils::initialize(&pool).await;

let mut submissions = vec![
Submission {
id: 1,
Expand Down
13 changes: 7 additions & 6 deletions atcoder-problems-backend/sql-client/tests/test_problem_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async fn get_points(pool: &PgPool) -> Vec<(String, Option<f64>)> {
.unwrap()
}

#[tokio::test]
async fn test_update_problem_solver_count() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_update_problem_solver_count(pool: PgPool) {
utils::initialize(&pool).await;

assert!(get_solver(&pool).await.is_empty());

Expand Down Expand Up @@ -79,12 +79,13 @@ async fn test_update_problem_solver_count() {
assert_eq!(get_solver(&pool).await, vec![("problem".to_string(), 3)]);
}

#[tokio::test]
async fn test_update_problem_points() {
#[sqlx::test]
async fn test_update_problem_points(pool: PgPool) {
let contest_id = "contest";
let problem_id = "problem";

let pool = utils::initialize_and_connect_to_test_sql().await;
utils::initialize(&pool).await;

pool.insert_contests(&[Contest {
id: contest_id.to_string(),
start_epoch_second: 1468670400,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use sql_client::internal::problem_list_manager::{ListItem, ProblemList, ProblemListManager};
use sql_client::{
internal::problem_list_manager::{ListItem, ProblemList, ProblemListManager},
PgPool,
};

mod utils;

#[tokio::test]
async fn test_problem_list_manager() {
#[sqlx::test]
async fn test_problem_list_manager(pool: PgPool) {
let internal_user_id = "user_id";
let atcoder_user_id = "atcoder_id";
let list_name = "list_name";
let problem_id = "problem_id";
let pool = utils::initialize_and_connect_to_test_sql().await;

utils::initialize(&pool).await;
utils::setup_internal_user(&pool, internal_user_id, atcoder_user_id).await;

assert!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,22 @@ async fn get_from(pool: &PgPool, table: Table) -> Vec<(String, String, i64)> {
.unwrap()
}

async fn setup_contests() -> PgPool {
let pool = utils::initialize_and_connect_to_test_sql().await;
async fn setup_contests(pool: &PgPool) {
utils::initialize(pool).await;

sqlx::query(
r"
INSERT INTO contests (id, start_epoch_second, duration_second, title, rate_change) VALUES
('contest1', 1, 0, '', ''), ('contest2', 1, 0, '', '');
",
)
.execute(&pool)
.execute(pool)
.await
.unwrap();

pool
}

#[tokio::test]
async fn test_problem_info_aggrefator() {
#[sqlx::test]
async fn test_problem_info_aggregator(pool: PgPool) {
let ignored_submission = vec![Submission {
id: 0,
problem_id: "problem1".to_owned(),
Expand Down Expand Up @@ -85,7 +84,7 @@ async fn test_problem_info_aggrefator() {
}];

{
let pool = setup_contests().await;
setup_contests(&pool).await;

pool.update_submissions(&ignored_submission).await.unwrap();
pool.update_submissions_of_problems().await.unwrap();
Expand All @@ -110,7 +109,7 @@ async fn test_problem_info_aggrefator() {
}

{
let pool = setup_contests().await;
setup_contests(&pool).await;

pool.update_submissions(&submissions2).await.unwrap();
pool.update_submissions_of_problems().await.unwrap();
Expand All @@ -130,7 +129,7 @@ async fn test_problem_info_aggrefator() {
}

{
let pool = setup_contests().await;
setup_contests(&pool).await;

pool.update_submissions(&submissions1).await.unwrap();
pool.update_submissions_of_problems().await.unwrap();
Expand All @@ -150,7 +149,7 @@ async fn test_problem_info_aggrefator() {
}

{
let pool = setup_contests().await;
setup_contests(&pool).await;

pool.update_submissions(&submissions2).await.unwrap();
pool.update_submissions_of_problems().await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use sql_client::internal::progress_reset_manager::{
ProgressResetItem, ProgressResetList, ProgressResetManager,
use sql_client::{
internal::progress_reset_manager::{
ProgressResetItem, ProgressResetList, ProgressResetManager,
},
PgPool,
};

mod utils;

#[tokio::test]
async fn test_progress_reset_manager() {
#[sqlx::test]
async fn test_progress_reset_manager(pool: PgPool) {
let internal_user_id = "user_id";
let atcoder_user_id = "atcoder_id";
let problem_id = "problem_id";
let reset_epoch_second = 42;
let pool = utils::initialize_and_connect_to_test_sql().await;

utils::initialize(&pool).await;
utils::setup_internal_user(&pool, internal_user_id, atcoder_user_id).await;

let list = pool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ async fn setup_contest_problems(pool: &PgPool) {
}
}

#[tokio::test]
async fn test_update_rated_point_sum() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_update_rated_point_sum(pool: PgPool) {
utils::initialize(&pool).await;

setup_contests(&pool).await;
setup_contest_problems(&pool).await;
Expand Down Expand Up @@ -247,9 +247,9 @@ async fn test_update_rated_point_sum() {
assert!(resp.is_err());
}

#[tokio::test]
async fn test_load_rated_point_sum_in_range() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_load_rated_point_sum_in_range(pool: PgPool) {
utils::initialize(&pool).await;

setup_contests(&pool).await;
setup_contest_problems(&pool).await;
Expand Down
15 changes: 9 additions & 6 deletions atcoder-problems-backend/sql-client/tests/test_simple_client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use sql_client::models::{Contest, Problem};
use sql_client::simple_client::SimpleClient;
use sql_client::PgPool;

mod utils;

#[tokio::test]
async fn test_insert_contests() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_insert_contests(pool: PgPool) {
utils::initialize(&pool).await;

assert!(pool.load_contests().await.unwrap().is_empty());
pool.insert_contests(&[Contest {
id: "contest1".to_string(),
Expand All @@ -31,9 +33,10 @@ async fn test_insert_contests() {
.unwrap();
}

#[tokio::test]
async fn test_insert_problems() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_insert_problems(pool: PgPool) {
utils::initialize(&pool).await;

assert!(pool.load_problems().await.unwrap().is_empty());
pool.insert_problems(&[Problem {
id: "problem1".to_string(),
Expand Down
8 changes: 5 additions & 3 deletions atcoder-problems-backend/sql-client/tests/test_streak.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use sql_client::models::UserStreak;
use sql_client::streak::StreakClient;
use sql_client::submission_client::{SubmissionClient, SubmissionRequest};
use sql_client::PgPool;

mod utils;

#[tokio::test]
async fn test_streak_ranking() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_streak_ranking(pool: PgPool) {
utils::initialize(&pool).await;

sqlx::query(
r"
INSERT INTO submissions (id, epoch_second, problem_id, contest_id, user_id, language, point, length, result) VALUES
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use sql_client::models::Submission;
use sql_client::submission_client::{SubmissionClient, SubmissionRequest};
use sql_client::PgPool;

mod utils;

#[tokio::test]
async fn test_submission_client() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_submission_client(pool: PgPool) {
utils::initialize(&pool).await;

sqlx::query(
r"
INSERT INTO submissions
Expand Down Expand Up @@ -128,9 +130,10 @@ async fn test_submission_client() {
assert_eq!(submissions.len(), 1);
}

#[tokio::test]
async fn test_update_submissions() {
let pool = utils::initialize_and_connect_to_test_sql().await;
#[sqlx::test]
async fn test_update_submissions(pool: PgPool) {
utils::initialize(&pool).await;

pool.update_submissions(&[Submission {
id: 0,
user_id: "old_user_name".to_owned(),
Expand Down
11 changes: 7 additions & 4 deletions atcoder-problems-backend/sql-client/tests/test_user_manager.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use sql_client::internal::user_manager::{InternalUserInfo, UserManager};
use sql_client::{
internal::user_manager::{InternalUserInfo, UserManager},
PgPool,
};

mod utils;

#[tokio::test]
async fn test_user_manager() {
#[sqlx::test]
async fn test_user_manager(pool: PgPool) {
let internal_user_id = "user_id";
let atcoder_user_id = "atcoder_id";
let pool = utils::initialize_and_connect_to_test_sql().await;
utils::initialize(&pool).await;

let get_result = pool.get_internal_user_info(internal_user_id).await;
assert!(
Expand Down
Loading