Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/backup/backupGetter.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/backup/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,56 +950,6 @@ describe('fails restoring backup with invalid compression config', () => {
it('cleans up', () => cleanupTestFood(client));
});

// describe("get all exising backups", () => {
// const BACKEND: Backend = 'filesystem';
// const BACKUP_ID = randomBackupId()
// const BACKUP_ID_PIZZA = BACKUP_ID + "-pizza";
// const BACKUP_ID_SOUP = BACKUP_ID + "-soup";

// const client = weaviate.client({
// scheme: "http",
// host: "localhost:8080",
// });

// it("sets up", () => createTestFoodSchemaAndData(client));

// it("creates backup pizza", () => {
// return client.backup.creator()
// .withIncludeClassNames(PIZZA_CLASS_NAME)
// .withBackend(BACKEND)
// .withBackupId(BACKUP_ID_PIZZA)
// .withWaitForCompletion(true)
// .do()
// .catch((err: any) => {throw new Error("should not fail on create backup: " + err)});
// });

// it("creates backup soup", () => {
// return client.backup.creator()
// .withIncludeClassNames(SOUP_CLASS_NAME)
// .withBackend(BACKEND)
// .withBackupId(BACKUP_ID_SOUP)
// .withWaitForCompletion(true)
// .do()
// .catch((err: any) => {throw new Error("should not fail on create backup: " + err)});
// });

// it("get all", () => {
// return client.backup.getter()
// .withBackend(BACKEND)
// .do()
// .then(allResponse => {
// expect(allResponse).toHaveLength(2);
// expect(allResponse).toEqual(expect.arrayContaining([
// expect.objectContaining({id: BACKUP_ID_PIZZA}),
// expect.objectContaining({id: BACKUP_ID_SOUP}),
// ]));
// })
// .catch((err: any) => {throw new Error("should not fail on getting all: " + err)});
// });

// it("cleans up", () => cleanupTestFood(client));
// });

function assertThatAllPizzasExist(client: WeaviateClient) {
return assertThatAllFoodObjectsExist(client, 'Pizza', 4);
}
Expand Down
18 changes: 14 additions & 4 deletions src/collections/backup/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
BackupStatusReturn,
} from './types.js';

export const backup = (connection: Connection) => {
export const backup = (connection: Connection): Backup => {
const parseStatus = (res: BackupCreateStatusResponse | BackupRestoreResponse): BackupStatusReturn => {
if (res.id === undefined) {
throw new WeaviateUnexpectedResponseError('Backup ID is undefined in response');
Expand Down Expand Up @@ -197,11 +197,14 @@
}
return status
? {
...parseResponse(res),
...status,
}
...parseResponse(res),

Check failure on line 200 in src/collections/backup/client.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
...status,

Check failure on line 201 in src/collections/backup/client.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
}

Check failure on line 202 in src/collections/backup/client.ts

View workflow job for this annotation

GitHub Actions / checks

Insert `··`
: parseResponse(res);
},
list: (backend: Backend): Promise<BackupReturn[]> => {
return connection.get<BackupReturn[]>(`/backups/${backend}`);
},
};
};

Expand Down Expand Up @@ -251,4 +254,11 @@
* @throws {WeaviateBackupCanceled} If the backup restoration is canceled.
*/
restore(args: BackupArgs<BackupConfigRestore>): Promise<BackupReturn>;

/** List existing backups (completed and in-progress) created in a given backend.
*
* @param {Backend} backend Backend whence to list backups.
* @returns {Promise<BackupReturn[]>} The response from Weaviate.
* */
list(backend: Backend): Promise<BackupReturn[]>;
}
56 changes: 52 additions & 4 deletions src/collections/backup/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
/* eslint-disable no-await-in-loop */
import { requireAtLeast } from '../../../test/version.js';
import { Backend } from '../../backup/index.js';
import weaviate, { Collection, WeaviateClient } from '../../index.js';

Expand Down Expand Up @@ -88,6 +89,23 @@ describe('Integration testing of backups', () => {
backend: res.backend as 'filesystem',
});
expect(status).not.toBe('SUCCESS'); // can be 'STARTED' or 'TRANSFERRING' depending on the speed of the test machine

// wait to complete so that other tests can run without colliding with Weaviate's lack of simultaneous backups
let wait = true;
while (wait) {
const { status, error } = await collection.backup.getCreateStatus({
backupId: res.id as string,
backend: res.backend as Backend,
});
if (status === 'SUCCESS') {
wait = false;
}
if (status === 'FAILED') {
throw new Error(`Backup creation failed: ${error}`);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
Comment on lines +92 to +107
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this wait to make sure the in-progress backup does not interfere with any tests that might follow.


return collection;
};

Expand All @@ -98,8 +116,38 @@ describe('Integration testing of backups', () => {
.then(getCollection)
.then(testCollectionWaitForCompletion)
.then(testCollectionNoWaitForCompletion));
});

function randomBackupId() {
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
requireAtLeast(1, 32, 0).it('get all exising backups', async () => {
await clientPromise.then(async (client) => {
await client.collections.create({ name: 'TestListBackups' }).then((col) => col.data.insert());

const wantBackups: string[] = [];
for (let i = 0; i < 3; i++) {
wantBackups.push(
await client.backup
.create({
backupId: randomBackupId(),
backend: 'filesystem',
includeCollections: ['TestListBackups'],
waitForCompletion: true,
})
.then((res) => {
return res.id;
})
);
}

const gotBackups: string[] = await client.backup
.list('filesystem')
.then((res) => res.map((bu) => bu.id));

// There may be other backups created in other tests;
expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length);
expect(gotBackups).toEqual(expect.arrayContaining(wantBackups));
});
});

function randomBackupId() {
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
});
Loading