Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

test: refactor tests#1310

Merged
alexander-fenster merged 5 commits intomainfrom
refactor-tests
Aug 12, 2022
Merged

test: refactor tests#1310
alexander-fenster merged 5 commits intomainfrom
refactor-tests

Conversation

@alexander-fenster
Copy link
Contributor

@alexander-fenster alexander-fenster commented Aug 11, 2022

Fixes googleapis/google-cloud-node-core#309.

This is a big refactor of the tests for google-gax that is long overdue.

I'm splitting system tests and browser tests into a separate subpackages (monorepo-style), each of which depend on the prepacked tarball of google-gax and other dependencies, simulating real life usage (so no npm link or anything like that, which confuses TypeScript compiler; just the real tarballs copied everywhere, so npm install works just as it would work in the real life).

Subpackages created in test/:

  • showcase-server: extracted from system tests; a helper to download and run gapic-showcase binary;
  • showcase-echo-client: a client library generated by gapic-generator-typescript based on Showcase protos that we will use for testing google-gax in the next two subpackages:
  • test-application: an application that launches showcase-server and uses showcase-echo-client to connect to it and test various google-gax features;
  • browser-test: a test suite that launches karma and runs some tests in a real Chromium browser.

This PR also contains some code fixes that will be submitted separately as #1311.

@alexander-fenster alexander-fenster requested a review from a team as a code owner August 11, 2022 07:06
@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Aug 11, 2022
@alexander-fenster alexander-fenster force-pushed the refactor-tests branch 5 times, most recently from 37adec2 to 6e1d14f Compare August 11, 2022 07:11
@alexander-fenster alexander-fenster force-pushed the refactor-tests branch 3 times, most recently from 7daa2a8 to 175e22f Compare August 11, 2022 07:27

// Save the auth object to the client, for use by other methods.
this.auth = this._gaxGrpc.auth as GoogleAuth;
this.auth = gaxGrpc.auth as GoogleAuth;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you removing gaxGrpc from the instantiated class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the reasons why the existing code does not work in browser with webpack.

To ask the client class to be browser-compatible and use fallback.ts implementation, we pass fallback: 'proto' or fallback: 'rest' to the constructor, so that the client won't use gRPC (which does not work in browser) and use proto-over-HTTP or REGAPIC (JSON-over-HTTP) instead.

const client = new library.WhateverClient({fallback: 'proto'}); // fallback: true also works

This affects how the client accesses gax (whether it would choose gax or gax.fallback), and what it will assign to its gaxGrpc, e.g. here is this place in Speech API.

Now, the Location service is a "mixin", basically, it's a separate client class that can be attached to the client that exposes Location API (that's why it lives in the common place, in google-gax).

If Speech client used fallback and created gaxGrpc from the fallback implementation, it must use the same gaxGrpc for all other clients (Location and LRO). For that to happen, the constructors for Location client and Operations client accept the existing instance of gaxGrpc (line 101 of this file). But I found that the instance that was passed is not actually used in some of these places, which makes the fallback client instantiate Location client that uses gRPC, so I'm changing all these places to use the instance that was passed down.

);
};
}
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see these errors being tested explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The browser use case tests it in test/browser-test/test.endtoend.ts, lines 86-92.
It seems the REGAPIC use case (the first throw) is indeed not tested, I added tests for all these cases to the test application (test/test-application/src/index.ts, functions testExpandThrows, testCollectThrows, testChatThrows). Thank you for noticing it!

@alexander-fenster alexander-fenster merged commit 5898da6 into main Aug 12, 2022
@alexander-fenster alexander-fenster deleted the refactor-tests branch August 12, 2022 21:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration tests refactor

2 participants