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
Show file tree
Hide file tree
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 a test for the mock server
Measure the latency between the original call and the mock server.
  • Loading branch information
danieljbruce committed Sep 22, 2023
commit 72f94926a9cbe9683c955048e2758750e7a97e74
2 changes: 2 additions & 0 deletions test/gapic-mocks/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import * as assert from 'assert';
import {before, describe} from 'mocha';
import * as ds from '../../src';
import * as proxyquire from 'proxyquire';
import * as gax from 'google-gax';
const {grpc} = new gax.GrpcClient();

function FakeV1() {}

Expand Down
63 changes: 63 additions & 0 deletions test/grpc-mocks/with-mock-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {before, describe} from 'mocha';
import {Datastore} from '../../src';
import {MockService} from '../util/mock-servers/mock-service';
import {MockServer} from '../util/mock-servers/mock-server';
import {DatastoreClientMockService} from '../util/mock-servers/service-implementations/datastore-client-mock-service';
// import assert from 'assert';

describe('Datastore/Unary', () => {
let server: MockServer;
let service: MockService;
let datastore: Datastore;

before(async () => {
// make sure we have everything initialized before starting tests
const port = await new Promise<string>(resolve => {
server = new MockServer(resolve);
});
datastore = new Datastore({
apiEndpoint: `localhost:${port}`,
});
service = new DatastoreClientMockService(server);
});

describe('some-test', async () => {
let callStartTime: number;
const emitTableNotExistsError = (stream: any) => {
const callEndTime = Date.now();
const timeElaspsed = callEndTime - callStartTime;
console.log(timeElaspsed);
};
before(async () => {
service.setService({
RunQuery: emitTableNotExistsError,
});
});
it.only('should not experience latency when making the grpc call', async () => {
// const startTime = Date.now();
callStartTime = Date.now();
const kind = 'Character';
const query = datastore.createQuery(kind);
await datastore.runQuery(query);
service.setService({
RunQuery: emitTableNotExistsError,
});
await datastore.runQuery(query);
// const [entities] = await datastore.runQuery(query);
});
});
});
63 changes: 63 additions & 0 deletions test/util/mock-servers/mock-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import {grpc} from 'google-gax';

const DEFAULT_PORT = 1234;

export class MockServer {
port: string;
services: Set<grpc.ServiceDefinition> = new Set();
server: grpc.Server;

constructor(
callback?: (port: string) => void,
port?: string | number | undefined
) {
const portString = Number(port ? port : DEFAULT_PORT).toString();
this.port = portString;
const server = new grpc.Server();
this.server = server;
server.bindAsync(
`localhost:${this.port}`,
grpc.ServerCredentials.createInsecure(),
() => {
server.start();
callback ? callback(portString) : undefined;
}
);
}

setService(
service: grpc.ServiceDefinition,
implementation: grpc.UntypedServiceImplementation
) {
if (this.services.has(service)) {
this.server.removeService(service);
} else {
this.services.add(service);
}
this.server.addService(service, implementation);
}

shutdown(callback: (err?: Error) => void) {
this.server.tryShutdown((err?: Error) => {
callback(err);
});
}
}
34 changes: 34 additions & 0 deletions test/util/mock-servers/mock-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import {grpc} from 'google-gax';

import {MockServer} from './mock-server';

export abstract class MockService {
abstract service: grpc.ServiceDefinition;
server: MockServer;

constructor(server: MockServer) {
this.server = server;
}

setService(implementation: grpc.UntypedServiceImplementation) {
this.server.setService(this.service, implementation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import grpc = require('@grpc/grpc-js');
import jsonProtos = require('../../../../protos/protos.json');
import protoLoader = require('@grpc/proto-loader');
import {MockService} from '../mock-service';

const packageDefinition = protoLoader.fromJSON(jsonProtos, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const proto = grpc.loadPackageDefinition(packageDefinition);

export class DatastoreClientMockService extends MockService {
service =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
proto.google.datastore.v1.Datastore.service;
}