Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New transaction feature #1140

Closed
Closed
Changes from 1 commit
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
Next Next commit
Test for time
Print the time difference for the transaction test to look at latency.
  • Loading branch information
danieljbruce committed Aug 21, 2023
commit c5f6954c6f12f9a71aa282bac54fd1f81534ac68
41 changes: 41 additions & 0 deletions system-test/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,31 @@ describe('Datastore', () => {
});

describe('transactions', () => {
it.only('should run in a transaction', async () => {
const key = datastore.key(['Company', 'Google']);
const obj = {
url: 'www.google.com',
};
const transaction = datastore.transaction();
const startTime = new Date().getTime();
function printTimeElasped(label: string) {
console.log(`${label}: ${new Date().getTime() - startTime}`);
}
printTimeElasped('Before begin transaction');
await transaction.run();
printTimeElasped('After begin transaction');
await transaction.get(key);
printTimeElasped('After fetch');
transaction.save({key, data: obj});
printTimeElasped('After save');
await transaction.commit();
printTimeElasped('After commit');
const [entity] = await datastore.get(key);
delete entity[datastore.KEY];
assert.deepStrictEqual(entity, obj);
});

/*
it('should run in a transaction', async () => {
const key = datastore.key(['Company', 'Google']);
const obj = {
Expand All @@ -1145,6 +1170,22 @@ describe('Datastore', () => {
delete entity[datastore.KEY];
assert.deepStrictEqual(entity, obj);
});
*/

it('should run in a transaction with transaction begin', async () => {
const key = datastore.key(['Company', 'Google']);
const obj = {
url: 'www.google.com',
};
const transaction = datastore.transaction();
await transaction.run();
await transaction.get(key);
transaction.save({key, data: obj});
await transaction.commit();
const [entity] = await datastore.get(key);
delete entity[datastore.KEY];
assert.deepStrictEqual(entity, obj);
});

it('should commit all saves and deletes at the end', async () => {
const deleteKey = datastore.key(['Company', 'Subway']);
Expand Down