11/* eslint-disable @typescript-eslint/no-non-null-assertion */
22/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
33/* eslint-disable no-await-in-loop */
4+ import { requireAtLeast } from '../../../test/version.js' ;
45import { Backend } from '../../backup/index.js' ;
56import weaviate , { Collection , WeaviateClient } from '../../index.js' ;
67
@@ -88,6 +89,23 @@ describe('Integration testing of backups', () => {
8889 backend : res . backend as 'filesystem' ,
8990 } ) ;
9091 expect ( status ) . not . toBe ( 'SUCCESS' ) ; // can be 'STARTED' or 'TRANSFERRING' depending on the speed of the test machine
92+
93+ // wait to complete so that other tests can run without colliding with Weaviate's lack of simultaneous backups
94+ let wait = true ;
95+ while ( wait ) {
96+ const { status, error } = await collection . backup . getCreateStatus ( {
97+ backupId : res . id as string ,
98+ backend : res . backend as Backend ,
99+ } ) ;
100+ if ( status === 'SUCCESS' ) {
101+ wait = false ;
102+ }
103+ if ( status === 'FAILED' ) {
104+ throw new Error ( `Backup creation failed: ${ error } ` ) ;
105+ }
106+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
107+ }
108+
91109 return collection ;
92110 } ;
93111
@@ -98,8 +116,37 @@ describe('Integration testing of backups', () => {
98116 . then ( getCollection )
99117 . then ( testCollectionWaitForCompletion )
100118 . then ( testCollectionNoWaitForCompletion ) ) ;
101- } ) ;
102119
103- function randomBackupId ( ) {
104- return 'backup-id-' + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER ) ;
105- }
120+ requireAtLeast ( 1 , 32 , 0 ) . it ( 'get all exising backups' , async ( ) => {
121+ await clientPromise . then ( async ( client ) => {
122+ await client . collections . create ( { name : 'TestListBackups' } ) . then ( ( col ) => col . data . insert ( ) ) ;
123+
124+ const wantBackups : string [ ] = [ ] ;
125+ for ( let i = 0 ; i < 3 ; i ++ ) {
126+ wantBackups . push (
127+ await client . backup . create ( {
128+ backupId : randomBackupId ( ) ,
129+ backend : 'filesystem' ,
130+ includeCollections : [ 'TestListBackups' ] ,
131+ waitForCompletion : true ,
132+ } )
133+ . then ( ( res ) => {
134+ return res . id ;
135+ } )
136+ ) ;
137+ }
138+
139+ const gotBackups : string [ ] = await client . backup
140+ . list ( 'filesystem' )
141+ . then ( ( res ) => res . map ( ( bu ) => bu . id ) ) ;
142+
143+ // There may be other backups created in other tests;
144+ expect ( gotBackups . length ) . toBeGreaterThanOrEqual ( wantBackups . length ) ;
145+ expect ( gotBackups ) . toEqual ( expect . arrayContaining ( wantBackups ) ) ;
146+ } ) ;
147+ } ) ;
148+
149+ function randomBackupId ( ) {
150+ return 'backup-id-' + Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER ) ;
151+ }
152+ } ) ;
0 commit comments