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

fix: read time should be used for transaction reads #1171

Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b66827e
Allow datastore projectId to be fetched from clien
danieljbruce Sep 7, 2023
684c469
Create a file for mocking out commits
danieljbruce Sep 20, 2023
1ec6ed2
Create a test to measure latency of call.
danieljbruce Sep 21, 2023
40213ca
Run the linting fixes
danieljbruce Sep 21, 2023
57e3b13
Add license header to top of test file
danieljbruce Sep 21, 2023
af56d91
Add comment for test for now
danieljbruce Sep 21, 2023
72f9492
Add a test for the mock server
danieljbruce Sep 22, 2023
194e109
Set current retry attempt to 0
danieljbruce Sep 22, 2023
22d5f54
Add a log for call time
danieljbruce Sep 22, 2023
81f5956
Add another mock
danieljbruce Sep 25, 2023
dc9dbb7
Eliminate code from the mock file
danieljbruce Oct 13, 2023
0ad0a57
Start off by adding read time to read options
danieljbruce Oct 13, 2023
e795c3a
Update the test to use transactions
danieljbruce Oct 13, 2023
851877c
Remove only
danieljbruce Oct 13, 2023
b9bfd79
Remove the before hook
danieljbruce Oct 13, 2023
617b013
Remove unnecessary cherry picked files
danieljbruce Oct 13, 2023
4a32ad3
Clean up PR diff
danieljbruce Oct 13, 2023
8f74353
clean up PR diff
danieljbruce Oct 13, 2023
4c9445c
Update the test so that it is run as a transaction
danieljbruce Oct 18, 2023
32729e1
Add an integration test
danieljbruce Oct 18, 2023
6ef2800
Merge branch 'main' of https://github.com/googleapis/nodejs-datastore…
danieljbruce Oct 30, 2023
1354b47
Linting fixing indents
danieljbruce Oct 30, 2023
80ca7ec
Merge branch 'main' into not-use-read-time-for-run-tx
danieljbruce Apr 4, 2024
136f1b7
Update the header
danieljbruce Apr 4, 2024
280244d
Merge branch 'not-use-read-time-for-run-tx' of https://github.com/dan…
danieljbruce Apr 4, 2024
95d0d54
Fix unit test
danieljbruce Apr 4, 2024
aa4f125
System test changes.
danieljbruce Apr 4, 2024
b78b091
Modify test
danieljbruce Apr 4, 2024
cc72220
Replace with less precise assert
danieljbruce Apr 4, 2024
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
Prev Previous commit
Next Next commit
Add an integration test
The integration test looks at the data from the snapshot read time for transactions and ensures that the read has no data thereby exercising the read time parameter.
  • Loading branch information
danieljbruce committed Oct 18, 2023
commit 32729e121b0b859d501d817c092ad1fc2d065291
32 changes: 28 additions & 4 deletions system-test/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,27 @@ describe('Datastore', () => {
});
});
describe('transactions', () => {
before(async () => {
// This 'sleep' function is used to ensure that when data is saved to datastore,
// the time on the server is far enough ahead to be sure to be later than timeBeforeDataCreation
// so that when we read at timeBeforeDataCreation we get a snapshot of data before the save.
const key = datastore.key(['Company', 'Google']);
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Save for a key so that a read time can be accessed for snapshot reads.
const emptyData = {
key,
data: {},
};
await datastore.save(emptyData);
timeBeforeDataCreation = await getReadTime([
{kind: 'Company', name: 'Google'},
]);
// Sleep for 3 seconds so that any future reads will be later than timeBeforeDataCreation.
await sleep(3000);
});

it('should run in a transaction', async () => {
const key = datastore.key(['Company', 'Google']);
const obj = {
Expand Down Expand Up @@ -1669,18 +1690,21 @@ describe('Datastore', () => {
assert.strictEqual(incompleteKey.path.length, 2);
});

it('should query within a transaction', async () => {
it('should query within a transaction at a previous read time', async () => {
const transaction = datastore.transaction();
await transaction.run();
const query = transaction.createQuery('Company');
let entities;
let entitiesBefore;
let entitiesNow;
try {
[entities] = await query.run();
[entitiesBefore] = await query.run({readTime: timeBeforeDataCreation});
[entitiesNow] = await query.run({});
} catch (e) {
await transaction.rollback();
return;
}
assert(entities!.length > 0);
assert.strictEqual(entitiesBefore!.length, 0);
assert(entitiesNow!.length > 0);
await transaction.commit();
});

Expand Down