File tree 4 files changed +15
-65
lines changed
4 files changed +15
-65
lines changed Original file line number Diff line number Diff line change 1
1
use sqlx:: pool:: PoolOptions ;
2
2
use sqlx:: { Connection , Database , Pool } ;
3
3
use std:: env;
4
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
5
4
6
5
pub fn setup_if_needed ( ) {
7
6
let _ = dotenvy:: dotenv ( ) ;
@@ -224,31 +223,3 @@ macro_rules! Postgres_query_for_test_prepared_type {
224
223
"SELECT ({0} is not distinct from $1)::int4, {0}, $2"
225
224
} ;
226
225
}
227
-
228
- /// Global lock that prevents multiple tests in this module to be executed at the same time.
229
- static GLOBAL_LOCK : AtomicBool = AtomicBool :: new ( false ) ;
230
-
231
- /// Simple lock guard that should not be used in production but that is `Send` (i.e. can easily be used with tokio).
232
- ///
233
- /// This may be helpful for tests that modify the database state, e.g. migrations.
234
- pub struct SimpleLockGuard ;
235
-
236
- impl SimpleLockGuard {
237
- /// Acquire global lock.
238
- pub fn acquire ( ) -> Self {
239
- loop {
240
- let was_locked = GLOBAL_LOCK . fetch_or ( true , Ordering :: SeqCst ) ;
241
- if !was_locked {
242
- break ;
243
- }
244
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
245
- }
246
- Self
247
- }
248
- }
249
-
250
- impl Drop for SimpleLockGuard {
251
- fn drop ( & mut self ) {
252
- GLOBAL_LOCK . store ( false , Ordering :: SeqCst ) ;
253
- }
254
- }
Original file line number Diff line number Diff line change 1
1
use sqlx:: migrate:: Migrator ;
2
2
use sqlx:: mysql:: { MySql , MySqlConnection } ;
3
+ use sqlx:: pool:: PoolConnection ;
3
4
use sqlx:: Executor ;
4
5
use sqlx:: Row ;
5
6
use std:: path:: Path ;
6
7
7
- use sqlx_test:: { new, SimpleLockGuard } ;
8
-
9
- #[ sqlx_macros:: test]
10
- async fn simple ( ) -> anyhow:: Result < ( ) > {
11
- let _guard = SimpleLockGuard :: acquire ( ) ;
12
-
13
- let mut conn = new :: < MySql > ( ) . await ?;
8
+ #[ sqlx:: test( migrations = false ) ]
9
+ async fn simple ( mut conn : PoolConnection < MySql > ) -> anyhow:: Result < ( ) > {
14
10
clean_up ( & mut conn) . await ?;
15
11
16
12
let migrator = Migrator :: new ( Path :: new ( "tests/mysql/migrations_simple" ) ) . await ?;
@@ -31,11 +27,8 @@ async fn simple() -> anyhow::Result<()> {
31
27
Ok ( ( ) )
32
28
}
33
29
34
- #[ sqlx_macros:: test]
35
- async fn reversible ( ) -> anyhow:: Result < ( ) > {
36
- let _guard = SimpleLockGuard :: acquire ( ) ;
37
-
38
- let mut conn = new :: < MySql > ( ) . await ?;
30
+ #[ sqlx:: test( migrations = false ) ]
31
+ async fn reversible ( mut conn : PoolConnection < MySql > ) -> anyhow:: Result < ( ) > {
39
32
clean_up ( & mut conn) . await ?;
40
33
41
34
let migrator = Migrator :: new ( Path :: new ( "tests/mysql/migrations_reversible" ) ) . await ?;
Original file line number Diff line number Diff line change 1
1
use sqlx:: migrate:: Migrator ;
2
+ use sqlx:: pool:: PoolConnection ;
2
3
use sqlx:: postgres:: { PgConnection , Postgres } ;
3
4
use sqlx:: Executor ;
4
5
use sqlx:: Row ;
5
6
use std:: path:: Path ;
6
7
7
- use sqlx_test:: { new, SimpleLockGuard } ;
8
-
9
- #[ sqlx_macros:: test]
10
- async fn simple ( ) -> anyhow:: Result < ( ) > {
11
- let _guard = SimpleLockGuard :: acquire ( ) ;
12
-
13
- let mut conn = new :: < Postgres > ( ) . await ?;
8
+ #[ sqlx:: test( migrations = false ) ]
9
+ async fn simple ( mut conn : PoolConnection < Postgres > ) -> anyhow:: Result < ( ) > {
14
10
clean_up ( & mut conn) . await ?;
15
11
16
12
let migrator = Migrator :: new ( Path :: new ( "tests/postgres/migrations_simple" ) ) . await ?;
@@ -31,11 +27,8 @@ async fn simple() -> anyhow::Result<()> {
31
27
Ok ( ( ) )
32
28
}
33
29
34
- #[ sqlx_macros:: test]
35
- async fn reversible ( ) -> anyhow:: Result < ( ) > {
36
- let _guard = SimpleLockGuard :: acquire ( ) ;
37
-
38
- let mut conn = new :: < Postgres > ( ) . await ?;
30
+ #[ sqlx:: test( migrations = false ) ]
31
+ async fn reversible ( mut conn : PoolConnection < Postgres > ) -> anyhow:: Result < ( ) > {
39
32
clean_up ( & mut conn) . await ?;
40
33
41
34
let migrator = Migrator :: new ( Path :: new ( "tests/postgres/migrations_reversible" ) ) . await ?;
Original file line number Diff line number Diff line change 1
1
use sqlx:: migrate:: Migrator ;
2
+ use sqlx:: pool:: PoolConnection ;
2
3
use sqlx:: sqlite:: { Sqlite , SqliteConnection } ;
3
4
use sqlx:: Executor ;
4
5
use sqlx:: Row ;
5
6
use std:: path:: Path ;
6
7
7
- use sqlx_test:: { new, SimpleLockGuard } ;
8
-
9
- #[ sqlx_macros:: test]
10
- async fn simple ( ) -> anyhow:: Result < ( ) > {
11
- let _guard = SimpleLockGuard :: acquire ( ) ;
12
-
13
- let mut conn = new :: < Sqlite > ( ) . await ?;
8
+ #[ sqlx:: test( migrations = false ) ]
9
+ async fn simple ( mut conn : PoolConnection < Sqlite > ) -> anyhow:: Result < ( ) > {
14
10
clean_up ( & mut conn) . await ?;
15
11
16
12
let migrator = Migrator :: new ( Path :: new ( "tests/sqlite/migrations_simple" ) ) . await ?;
@@ -31,11 +27,8 @@ async fn simple() -> anyhow::Result<()> {
31
27
Ok ( ( ) )
32
28
}
33
29
34
- #[ sqlx_macros:: test]
35
- async fn reversible ( ) -> anyhow:: Result < ( ) > {
36
- let _guard = SimpleLockGuard :: acquire ( ) ;
37
-
38
- let mut conn = new :: < Sqlite > ( ) . await ?;
30
+ #[ sqlx:: test( migrations = false ) ]
31
+ async fn reversible ( mut conn : PoolConnection < Sqlite > ) -> anyhow:: Result < ( ) > {
39
32
clean_up ( & mut conn) . await ?;
40
33
41
34
let migrator = Migrator :: new ( Path :: new ( "tests/sqlite/migrations_reversible" ) ) . await ?;
You can’t perform that action at this time.
0 commit comments