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
Create a test to measure latency of call.
To prove that the change works to reduce latency, a test is written. The test checks to see that the amount of time that passes between the time when the initial call is made in the user’s code and the time when the call reaches the gapic layer is sufficiently small. It will be a very small amount of time if the program does not need to do an auth lookup.
  • Loading branch information
danieljbruce committed Sep 21, 2023
commit 1ec6ed26258ae6c790a83ea1b2c3b227c4b8fa20
46 changes: 41 additions & 5 deletions test/gapic-mocks/commit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as assert from 'assert';
import {before, describe} from 'mocha';
import * as ds from '../../src';
import * as proxyquire from 'proxyquire';

function FakeV1() {}

describe('Commit', () => {
let Datastore: typeof ds.Datastore;
Expand All @@ -8,9 +12,32 @@ describe('Commit', () => {

const PROJECT_ID = 'project-id';
const NAMESPACE = 'namespace';
const clientName = 'DatastoreClient';

// This function is used for doing assertion checks.
// The idea is to check that the right request gets passed to the commit function in the Gapic layer.
function setCommitComparison(compareFn: (request: any) => void) {
const dataClient = datastore.clients_.get(clientName);
if (dataClient) {
dataClient.commit = (
request: any,
options: any,
callback: (err?: unknown) => void
) => {
try {
compareFn(request);
} catch (e) {
callback(e);
}
callback();
};
}
}

before(() => {
const clientName = 'DatastoreClient';
Datastore = proxyquire('../../src', {
'./v1': FakeV1,
}).Datastore;
const options = {
projectId: PROJECT_ID,
namespace: NAMESPACE,
Expand All @@ -22,10 +49,19 @@ describe('Commit', () => {
// We don't want to make this call because it would make a grpc request.
// So we just add the data client to the map.
const gapic = Object.freeze({
v1: require('../src/v1'),
v1: require('../../src/v1'),
});
datastore.clients_.set(clientName, new gapic.v1[clientName](options));
// Mock out commit and just have it pass back the information passed into it through the callback.
// This way we can easily use assertion checks to see what reached the gapic layer.
});
});

it('should not experience latency when fetching the project', async () => {
const startTime = Date.now();
setCommitComparison(() => {
const endTime = Date.now();
const callTime = endTime - startTime;
// Testing locally reveals callTime is usually about 1.
assert(callTime < 100);
});
await datastore.save([]);
});
});
Loading