Since DB tests execute diesel migrations automatically, concurrent
execution causes flaky failures from simultaneous migrations. This can
be worked around using `cargo test --workspace -- --test-threads=1`,
which is what the CI config does, but this is not intuitive for
newcomer developers and unnecessarily slows down the test suite for
the majority of tests which are safe to run concurrently. This fixes
this issue by integrating with the small test crate `serial_test` and
using it to explicitly mark DB tests to run sequentially while
allowing all other tests to run in parallel.
Additionally, this greatly improves the speed of `cargo test` by
disabling doc-tests in all crates, since these are aren't currently
used and cargo's doc-test pass, even when no doc-tests exist, has
significant overhead. On my machine, this change significantly
improves test suite times by about 85%, making it much more practical
to develop with tools like `cargo watch` auto-running tests.
32 files changed:
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: 1
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: 1
commands:
- sudo apt-get update
- sudo apt-get -y install --no-install-recommends espeak postgresql-client
commands:
- sudo apt-get update
- sudo apt-get -y install --no-install-recommends espeak postgresql-client
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: 1
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: 1
commands:
- apt-get update
- apt-get -y install --no-install-recommends espeak postgresql-client libssl-dev pkg-config libpq-dev
commands:
- apt-get update
- apt-get -y install --no-install-recommends espeak postgresql-client libssl-dev pkg-config libpq-dev
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "activitystreams"
version = "0.7.0-alpha.10"
[[package]]
name = "activitystreams"
version = "0.7.0-alpha.10"
"regex",
"serde 1.0.123",
"serde_json",
"regex",
"serde 1.0.123",
"serde_json",
"sha2",
"strum",
"strum_macros",
"sha2",
"strum",
"strum_macros",
"lemmy_db_schema",
"log",
"serde 1.0.123",
"lemmy_db_schema",
"log",
"serde 1.0.123",
+[[package]]
+name = "serial_test"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d"
+dependencies = [
+ "lazy_static",
+ "parking_lot",
+ "serial_test_derive",
+]
+
+[[package]]
+name = "serial_test_derive"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "sha-1"
version = "0.8.2"
[[package]]
name = "sha-1"
version = "0.8.2"
version = "0.0.1"
edition = "2018"
version = "0.0.1"
edition = "2018"
+[lib]
+doctest = false
+
[lib]
name = "lemmy_api"
path = "src/lib.rs"
[lib]
name = "lemmy_api"
path = "src/lib.rs"
[dependencies]
lemmy_apub = { path = "../apub" }
[dependencies]
lemmy_apub = { path = "../apub" }
[lib]
name = "lemmy_apub"
path = "src/lib.rs"
[lib]
name = "lemmy_apub"
path = "src/lib.rs"
[dependencies]
lemmy_utils = { path = "../utils" }
[dependencies]
lemmy_utils = { path = "../utils" }
[lib]
name = "lemmy_db_queries"
path = "src/lib.rs"
[lib]
name = "lemmy_db_queries"
path = "src/lib.rs"
[dependencies]
lemmy_utils = { path = "../utils" }
[dependencies]
lemmy_utils = { path = "../utils" }
lazy_static = "1.4.0"
regex = "1.4.3"
bcrypt = "0.9.0"
lazy_static = "1.4.0"
regex = "1.4.3"
bcrypt = "0.9.0"
+
+[dev-dependencies]
+serial_test = "0.5.1"
\ No newline at end of file
post::{Post, PostForm},
user::{UserForm, User_},
};
post::{Post, PostForm},
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
post::{Post, PostForm},
user::{UserForm, User_},
};
post::{Post, PostForm},
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
site::{Site, SiteForm},
user::{UserForm, User_},
};
site::{Site, SiteForm},
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate diesel_migrations;
+#[cfg(test)]
+extern crate serial_test;
+
use diesel::{result::Error, *};
use lemmy_db_schema::Url;
use regex::Regex;
use diesel::{result::Error, *};
use lemmy_db_schema::Url;
use regex::Regex;
user::{UserForm, User_},
};
use serde_json::Value;
user::{UserForm, User_},
};
use serde_json::Value;
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
post::*,
user::{UserForm, User_},
};
post::*,
user::{UserForm, User_},
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
SortType,
};
use lemmy_db_schema::source::{community::*, user::*};
SortType,
};
use lemmy_db_schema::source::{community::*, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
mod tests {
use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
mod tests {
use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
SortType,
};
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
SortType,
};
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
community::{Community, CommunityForm},
user::*,
};
community::{Community, CommunityForm},
user::*,
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
SortType,
};
use lemmy_db_schema::source::{private_message::*, user::*};
SortType,
};
use lemmy_db_schema::source::{private_message::*, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
user::*,
user_mention::*,
};
user::*,
user_mention::*,
};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
version = "0.1.0"
edition = "2018"
version = "0.1.0"
edition = "2018"
+[lib]
+doctest = false
+
[dependencies]
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
chrono = { version = "0.4.19", features = ["serde"] }
[dependencies]
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
chrono = { version = "0.4.19", features = ["serde"] }
version = "0.1.0"
edition = "2018"
version = "0.1.0"
edition = "2018"
+[lib]
+doctest = false
+
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
serde = { version = "1.0.123", features = ["derive"] }
log = "0.4.14"
url = "2.2.0"
serde = { version = "1.0.123", features = ["derive"] }
log = "0.4.14"
url = "2.2.0"
+
+[dev-dependencies]
+serial_test = "0.5.1"
\ No newline at end of file
SortType,
};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
SortType,
};
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
+#[cfg(test)]
+extern crate serial_test;
+
pub mod comment_report_view;
pub mod comment_view;
pub mod post_report_view;
pub mod comment_report_view;
pub mod comment_view;
pub mod post_report_view;
SortType,
};
use lemmy_db_schema::source::{community::*, post::*, user::*};
SortType,
};
use lemmy_db_schema::source::{community::*, post::*, user::*};
+ use serial_test::serial;
fn test_crud() {
let conn = establish_unpooled_connection();
fn test_crud() {
let conn = establish_unpooled_connection();
version = "0.1.0"
edition = "2018"
version = "0.1.0"
edition = "2018"
+[lib]
+doctest = false
+
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
version = "0.1.0"
edition = "2018"
version = "0.1.0"
edition = "2018"
+[lib]
+doctest = false
+
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
lemmy_db_schema = { path = "../db_schema" }
version = "0.1.0"
edition = "2018"
version = "0.1.0"
edition = "2018"
+[lib]
+doctest = false
+
[dependencies]
lemmy_utils = { path = "../utils" }
lemmy_websocket = { path = "../websocket" }
[dependencies]
lemmy_utils = { path = "../utils" }
lemmy_websocket = { path = "../websocket" }
[lib]
name = "lemmy_structs"
path = "src/lib.rs"
[lib]
name = "lemmy_structs"
path = "src/lib.rs"
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
[dependencies]
lemmy_db_queries = { path = "../db_queries" }
[lib]
name = "lemmy_utils"
path = "src/lib.rs"
[lib]
name = "lemmy_utils"
path = "src/lib.rs"
[dependencies]
regex = "1.4.3"
[dependencies]
regex = "1.4.3"
[lib]
name = "lemmy_websocket"
path = "src/lib.rs"
[lib]
name = "lemmy_websocket"
path = "src/lib.rs"
[dependencies]
lemmy_utils = { path = "../utils" }
[dependencies]
lemmy_utils = { path = "../utils" }