@@ -5,52 +5,58 @@ import { collections } from "$lib/server/database";
5
5
6
6
const LOCK_KEY = "migrations.test" ;
7
7
8
- describe ( "migrations" , ( ) => {
9
- it ( "should not have duplicates guid" , async ( ) => {
10
- const guids = migrations . map ( ( m ) => m . _id . toString ( ) ) ;
11
- const uniqueGuids = [ ...new Set ( guids ) ] ;
12
- expect ( uniqueGuids . length ) . toBe ( guids . length ) ;
13
- } ) ;
8
+ describe (
9
+ "migrations" ,
10
+ {
11
+ retry : 3 ,
12
+ } ,
13
+ ( ) => {
14
+ it ( "should not have duplicates guid" , async ( ) => {
15
+ const guids = migrations . map ( ( m ) => m . _id . toString ( ) ) ;
16
+ const uniqueGuids = [ ...new Set ( guids ) ] ;
17
+ expect ( uniqueGuids . length ) . toBe ( guids . length ) ;
18
+ } ) ;
14
19
15
- it ( "should acquire only one lock on DB" , async ( ) => {
16
- const results = await Promise . all ( new Array ( 1000 ) . fill ( 0 ) . map ( ( ) => acquireLock ( LOCK_KEY ) ) ) ;
17
- const locks = results . filter ( ( r ) => r ) ;
20
+ it ( "should acquire only one lock on DB" , async ( ) => {
21
+ const results = await Promise . all ( new Array ( 1000 ) . fill ( 0 ) . map ( ( ) => acquireLock ( LOCK_KEY ) ) ) ;
22
+ const locks = results . filter ( ( r ) => r ) ;
18
23
19
- const semaphores = await collections . semaphores . find ( { } ) . toArray ( ) ;
24
+ const semaphores = await collections . semaphores . find ( { } ) . toArray ( ) ;
20
25
21
- expect ( locks . length ) . toBe ( 1 ) ;
22
- expect ( semaphores ) . toBeDefined ( ) ;
23
- expect ( semaphores . length ) . toBe ( 1 ) ;
24
- expect ( semaphores ?. [ 0 ] . key ) . toBe ( LOCK_KEY ) ;
25
- } ) ;
26
+ expect ( locks . length ) . toBe ( 1 ) ;
27
+ expect ( semaphores ) . toBeDefined ( ) ;
28
+ expect ( semaphores . length ) . toBe ( 1 ) ;
29
+ expect ( semaphores ?. [ 0 ] . key ) . toBe ( LOCK_KEY ) ;
30
+ } ) ;
26
31
27
- it ( "should read the lock correctly" , async ( ) => {
28
- const lockId = await acquireLock ( LOCK_KEY ) ;
29
- assert ( lockId ) ;
30
- expect ( await isDBLocked ( LOCK_KEY ) ) . toBe ( true ) ;
31
- expect ( ! ! ( await acquireLock ( LOCK_KEY ) ) ) . toBe ( false ) ;
32
- await releaseLock ( LOCK_KEY , lockId ) ;
33
- expect ( await isDBLocked ( LOCK_KEY ) ) . toBe ( false ) ;
34
- } ) ;
32
+ it ( "should read the lock correctly" , async ( ) => {
33
+ const lockId = await acquireLock ( LOCK_KEY ) ;
34
+ assert ( lockId ) ;
35
+ expect ( await isDBLocked ( LOCK_KEY ) ) . toBe ( true ) ;
36
+ expect ( ! ! ( await acquireLock ( LOCK_KEY ) ) ) . toBe ( false ) ;
37
+ await releaseLock ( LOCK_KEY , lockId ) ;
38
+ expect ( await isDBLocked ( LOCK_KEY ) ) . toBe ( false ) ;
39
+ } ) ;
35
40
36
- it ( "should refresh the lock" , async ( ) => {
37
- const lockId = await acquireLock ( LOCK_KEY ) ;
41
+ it ( "should refresh the lock" , async ( ) => {
42
+ const lockId = await acquireLock ( LOCK_KEY ) ;
38
43
39
- assert ( lockId ) ;
44
+ assert ( lockId ) ;
40
45
41
- // get the updatedAt time
46
+ // get the updatedAt time
42
47
43
- const updatedAtInitially = ( await collections . semaphores . findOne ( { } ) ) ?. updatedAt ;
48
+ const updatedAtInitially = ( await collections . semaphores . findOne ( { } ) ) ?. updatedAt ;
44
49
45
- await refreshLock ( LOCK_KEY , lockId ) ;
50
+ await refreshLock ( LOCK_KEY , lockId ) ;
46
51
47
- const updatedAtAfterRefresh = ( await collections . semaphores . findOne ( { } ) ) ?. updatedAt ;
52
+ const updatedAtAfterRefresh = ( await collections . semaphores . findOne ( { } ) ) ?. updatedAt ;
48
53
49
- expect ( updatedAtInitially ) . toBeDefined ( ) ;
50
- expect ( updatedAtAfterRefresh ) . toBeDefined ( ) ;
51
- expect ( updatedAtInitially ) . not . toBe ( updatedAtAfterRefresh ) ;
52
- } ) ;
53
- } ) ;
54
+ expect ( updatedAtInitially ) . toBeDefined ( ) ;
55
+ expect ( updatedAtAfterRefresh ) . toBeDefined ( ) ;
56
+ expect ( updatedAtInitially ) . not . toBe ( updatedAtAfterRefresh ) ;
57
+ } ) ;
58
+ }
59
+ ) ;
54
60
55
61
afterEach ( async ( ) => {
56
62
await collections . semaphores . deleteMany ( { } ) ;
0 commit comments