]> Untitled Git - lemmy.git/commitdiff
Support plain `cargo test` and disable unused doctests for speed
authorAndrew Yoon <andrew@nothing-to-say.org>
Thu, 25 Feb 2021 19:43:39 +0000 (14:43 -0500)
committerAndrew Yoon <andrew@nothing-to-say.org>
Thu, 25 Feb 2021 20:44:30 +0000 (15:44 -0500)
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:
.drone.yml
Cargo.lock
Cargo.toml
crates/api/Cargo.toml
crates/apub/Cargo.toml
crates/db_queries/Cargo.toml
crates/db_queries/src/aggregates/comment_aggregates.rs
crates/db_queries/src/aggregates/community_aggregates.rs
crates/db_queries/src/aggregates/post_aggregates.rs
crates/db_queries/src/aggregates/site_aggregates.rs
crates/db_queries/src/aggregates/user_aggregates.rs
crates/db_queries/src/lib.rs
crates/db_queries/src/source/activity.rs
crates/db_queries/src/source/comment.rs
crates/db_queries/src/source/community.rs
crates/db_queries/src/source/moderator.rs
crates/db_queries/src/source/password_reset_request.rs
crates/db_queries/src/source/post.rs
crates/db_queries/src/source/private_message.rs
crates/db_queries/src/source/user.rs
crates/db_queries/src/source/user_mention.rs
crates/db_schema/Cargo.toml
crates/db_views/Cargo.toml
crates/db_views/src/comment_view.rs
crates/db_views/src/lib.rs
crates/db_views/src/post_view.rs
crates/db_views_actor/Cargo.toml
crates/db_views_moderator/Cargo.toml
crates/routes/Cargo.toml
crates/structs/Cargo.toml
crates/utils/Cargo.toml
crates/websocket/Cargo.toml

index 807d6c991cc1067a889696dc9a17358e287df68c..b6fa86db599231892d9ce38e8c099d5239982540 100644 (file)
@@ -29,7 +29,6 @@ steps:
     environment:
       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
       RUST_BACKTRACE: 1
-      RUST_TEST_THREADS: 1
     commands:
       - sudo apt-get update
       - sudo apt-get -y install --no-install-recommends espeak postgresql-client
@@ -107,7 +106,6 @@ steps:
     environment:
       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
       RUST_BACKTRACE: 1
-      RUST_TEST_THREADS: 1
     commands:
       - apt-get update
       - apt-get -y install --no-install-recommends espeak postgresql-client libssl-dev pkg-config libpq-dev
index 2edcca8d7d3dd89bbc53bf0f285eb07cd6f2502c..cdf7f679c859fa7a97d19a53ea2aea430f0b0c1d 100644 (file)
@@ -1,5 +1,7 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
+version = 3
+
 [[package]]
 name = "activitystreams"
 version = "0.7.0-alpha.10"
@@ -1818,6 +1820,7 @@ dependencies = [
  "regex",
  "serde 1.0.123",
  "serde_json",
+ "serial_test",
  "sha2",
  "strum",
  "strum_macros",
@@ -1845,6 +1848,7 @@ dependencies = [
  "lemmy_db_schema",
  "log",
  "serde 1.0.123",
+ "serial_test",
  "url",
 ]
 
@@ -3080,6 +3084,28 @@ dependencies = [
  "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"
index edec85f60ee6d394eafa687b6d60e53febed5ddf..ab7d90198390b8f7bda8457bfef93b1bf4210651 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_server"
 version = "0.0.1"
 edition = "2018"
 
+[lib]
+doctest = false
+
 [profile.dev]
 debug = 0
 
index e3226eb8581ca2f104474a2192978af5e855c924..299121a6eba68740720c4b58cda9ef4fdfccc81c 100644 (file)
@@ -7,6 +7,7 @@ edition = "2018"
 [lib]
 name = "lemmy_api"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 lemmy_apub = { path = "../apub" }
index f2ad968388fbf6e480375895273f46b1b0b1fa91..9dd9bc82f5dbc5557ed83185dc09bd67287754bd 100644 (file)
@@ -7,6 +7,7 @@ edition = "2018"
 [lib]
 name = "lemmy_apub"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 lemmy_utils = { path = "../utils" }
index c396b39a3e2497bd985507491ffccbac59b970c0..0e489e2289339d392df97a0abef81a448a5846ae 100644 (file)
@@ -6,6 +6,7 @@ edition = "2018"
 [lib]
 name = "lemmy_db_queries"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 lemmy_utils = { path = "../utils" }
@@ -23,3 +24,6 @@ url = { version = "2.2.0", features = ["serde"] }
 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
index a4db471b65343708a7188d5df6eb848abd901979..0826ae0d4b4dfed9b5a923f043a2e9a23df5879a 100644 (file)
@@ -37,8 +37,10 @@ mod tests {
     post::{Post, PostForm},
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index f5cd577e437efef958d39f18e43bcb3692e78f40..ee60da9b287e8c599233aebc02952b89553a84f3 100644 (file)
@@ -41,8 +41,10 @@ mod tests {
     post::{Post, PostForm},
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index fa8b69255c755e88cac92cecc46b5714b73ac82a..404257a7b75f6831f94a099cde7062233a2da1b9 100644 (file)
@@ -41,8 +41,10 @@ mod tests {
     post::{Post, PostForm, PostLike, PostLikeForm},
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 46db2f0cd4eb926a05406b8f6195f32b2012c58f..81afed5c49d6540e043d3720b016479a8f5eae74 100644 (file)
@@ -39,8 +39,10 @@ mod tests {
     site::{Site, SiteForm},
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index fcda1d462cc76745baddb574203affa692136466..bdd16932a101a4f0bea727eda5c5e18ec52fcea8 100644 (file)
@@ -37,8 +37,10 @@ mod tests {
     post::{Post, PostForm, PostLike, PostLikeForm},
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index bf0de33662a0f5cfe46f0f2cde416cff213b3236..5667b4262837abfcf375f13b0e318ecb5c2c4e74 100644 (file)
@@ -9,6 +9,9 @@ extern crate lazy_static;
 #[macro_use]
 extern crate diesel_migrations;
 
+#[cfg(test)]
+extern crate serial_test;
+
 use diesel::{result::Error, *};
 use lemmy_db_schema::Url;
 use regex::Regex;
index 59e1754aa40f169dbec4621545bb423e8718df66..cf946d67dabdd2792492b2f7f3b83b09ff9196d5 100644 (file)
@@ -133,8 +133,10 @@ mod tests {
     user::{UserForm, User_},
   };
   use serde_json::Value;
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 709a8aa39b9bde3a4a20c5bedb20ee2ea95aaacf..918ae49774de43698c7a964ca689da9835119499 100644 (file)
@@ -212,8 +212,10 @@ mod tests {
     post::*,
     user::{UserForm, User_},
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 08421bd5d67d3103b77af19687af01e858a66f68..6a19d2211ed251c2c7476c026ec38ac81361caf1 100644 (file)
@@ -340,8 +340,10 @@ mod tests {
     SortType,
   };
   use lemmy_db_schema::source::{community::*, user::*};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 9b6e58edf340eeee1a1ebc547fa4c020829bfc77..469ada089f1f2eb6dacbfb2e199189216be3c717 100644 (file)
@@ -199,9 +199,11 @@ impl Crud<ModAddForm> for ModAdd {
 mod tests {
   use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
   use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
+  use serial_test::serial;
 
   // use Crud;
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index f58d2c014a2cd042403832aeb67a049668de0e6a..600037d8ac1719df6a6e8c150fb27f74b40e33a9 100644 (file)
@@ -80,8 +80,10 @@ mod tests {
     SortType,
   };
   use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 1c19e53d0326aad41f2b437f682771858873b40e..f6b1342ef083d2e6dfcef3e3ab180c185fe72195 100644 (file)
@@ -231,8 +231,10 @@ mod tests {
     community::{Community, CommunityForm},
     user::*,
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 8cace93841a49b9c74566a269100375c806619e5..f1908bc148cdec965585cd099f4b6d14dc2fef3f 100644 (file)
@@ -147,8 +147,10 @@ mod tests {
     SortType,
   };
   use lemmy_db_schema::source::{private_message::*, user::*};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 5f3fa6cbb33382fdc216402abafbb705ba574dc5..20b187b46fbe3ae686fba42e3c4b35eebf472ed0 100644 (file)
@@ -379,8 +379,10 @@ impl User for User_ {
 #[cfg(test)]
 mod tests {
   use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index b0c97572f691193e03ed38399b1f7a7390e6ac9c..5efc95bf66c1c553a2760f879fdf0050e4060db2 100644 (file)
@@ -81,8 +81,10 @@ mod tests {
     user::*,
     user_mention::*,
   };
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index a175f80e425f458edc429e066650bc0391f4745d..b637c0222f1039cb7a70ebbf6a88e5d62571a14f 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_db_schema"
 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"] }
index 175e6eae6509e99c659a6ce6be54b68746479679..e44f414a6151ff941dcf94a40c748e06d9843511 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_db_views"
 version = "0.1.0"
 edition = "2018"
 
+[lib]
+doctest = false
+
 [dependencies]
 lemmy_db_queries = { path = "../db_queries" }
 lemmy_db_schema = { path = "../db_schema" }
@@ -10,3 +13,6 @@ diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json
 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
index 4f9a6a5f71ceae204cf80d69f968fed2f816ae05..56b22a7f00aaaae52e13ba08f096c61efe7c32fa 100644 (file)
@@ -443,8 +443,10 @@ mod tests {
     SortType,
   };
   use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index b46ec5a4645f32f852ae4902c4ea830a3d1f6860..a9369ed2496f5775773d4e8b7ef67cd35152d327 100644 (file)
@@ -1,3 +1,6 @@
+#[cfg(test)]
+extern crate serial_test;
+
 pub mod comment_report_view;
 pub mod comment_view;
 pub mod post_report_view;
index ed1ef4ce1419158457ded6c966ecab6fb653878c..e7b488275f7e9cf5d4a7ed2bbb96a63289ce9895 100644 (file)
@@ -434,8 +434,10 @@ mod tests {
     SortType,
   };
   use lemmy_db_schema::source::{community::*, post::*, user::*};
+  use serial_test::serial;
 
   #[test]
+  #[serial]
   fn test_crud() {
     let conn = establish_unpooled_connection();
 
index 8e86d4c0ae333f81b3679f99ee450737141cc8c4..e237941e192a34c6abb31933da304c9bdfad975e 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_db_views_actor"
 version = "0.1.0"
 edition = "2018"
 
+[lib]
+doctest = false
+
 [dependencies]
 lemmy_db_queries = { path = "../db_queries" }
 lemmy_db_schema = { path = "../db_schema" }
index aef6abdc3e7c1eea0fefa38b7ed24973daeb374f..9df01522dd15ba32f92670ed7186f94f293444a2 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_db_views_moderator"
 version = "0.1.0"
 edition = "2018"
 
+[lib]
+doctest = false
+
 [dependencies]
 lemmy_db_queries = { path = "../db_queries" }
 lemmy_db_schema = { path = "../db_schema" }
index 0c5eac66592a1ff729cd8b91847f3bb7f13a6cbb..b71ffca7037faf4d6275271d5ad9b6dfdaa2669d 100644 (file)
@@ -3,6 +3,9 @@ name = "lemmy_routes"
 version = "0.1.0"
 edition = "2018"
 
+[lib]
+doctest = false
+
 [dependencies]
 lemmy_utils = { path = "../utils" }
 lemmy_websocket = { path = "../websocket" }
index f895a8c954f961d4b904f1902c51158c7d11f07f..de4f38cbf310563383329715fcb9cb71c45c8711 100644 (file)
@@ -7,6 +7,7 @@ edition = "2018"
 [lib]
 name = "lemmy_structs"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 lemmy_db_queries = { path = "../db_queries" }
index c10b7c2c7ffec0afdd14d4bd219c4e5ea50432a5..3308669a4463464d72882c5ee1344c3debd42b41 100644 (file)
@@ -6,6 +6,7 @@ edition = "2018"
 [lib]
 name = "lemmy_utils"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 regex = "1.4.3"
index 1cb71ea1df7f6bff30150712fda89c19fca50bed..3116d71e75f13921e4420724f942d59de8ac1c9a 100644 (file)
@@ -7,6 +7,7 @@ edition = "2018"
 [lib]
 name = "lemmy_websocket"
 path = "src/lib.rs"
+doctest = false
 
 [dependencies]
 lemmy_utils = { path = "../utils" }