tests(pubsub): integrate pub/sub sample system tests that are still useful - #8091
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive testing framework for Pub/Sub, including unit tests for common utilities and system tests for core operations like topic creation and message publishing. It also adds a TestResources class to manage resource lifecycle and prevent naming conflicts. Key feedback includes addressing a potential memory leak in the message listener timeout logic, improving the testability of the cleanup utility by using the provided timestamp provider instead of a direct call to Date.now(), and removing redundant any type assertions for better type safety.
|
This is obviously not running. |
The tests are running again now that it's moved to GCB. |
|
@shivanee-p Unfortunately this still requires some work to get CI passing. Maybe this is a hole in the new assigner script? Or was reassigning existing issues part of the initial cleanup pass? |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ca5cc15 to
b215ee1
Compare
|
The old branch had unfortunately become very crufty from merges, so I refactored it. |
|
|
||
| const message = await new Promise<Message>((resolve, reject) => { | ||
| const timeout = setTimeout(() => reject(new Error('Timeout waiting for Avro record')), 15000); | ||
| subscription.once('message', (m: Message) => { |
There was a problem hiding this comment.
Do we need to remove this listener if we hit timeout (like you did in pubsub.ts?)
There was a problem hiding this comment.
Sorry I didn't point it out before, there are several cases like this remaining in the PR. Can you please address those, too?
| "@types/tmp": "^0.2.6", | ||
| "avro-js": "^1.12.1", | ||
| "c8": "^10.1.3", | ||
| "chai": "^6.2.2", |
There was a problem hiding this comment.
do we use chai consistently in our tests?
If we can workaround features of built-in assert, maybe we should stick to that.
Generally, I'd prefer to have consistent APIs across tests. Can you consider a follow-up PR to move all the assertions to chai, if that's the best thing?
There was a problem hiding this comment.
We used to, we don't anymore - we're trying to move to the simpler built-in assert. I'll remove this.
| // I don't like that these two files (this plus ".test") are duplicated | ||
| // across the two test structures, but because of the tangle of rootDirs | ||
| // and package.json "files", it's hard to avoid it. |
There was a problem hiding this comment.
I like the idea of testresources, is there a way we can avoid the duplication? Could this be put in some shared test-utils dependency?
There was a problem hiding this comment.
There's not really a good candidate right now for a separate library - I like the idea of making a test-utils in core somewhere. Especially in goofy cases like this. But it generally seems useful for the handwritten libraries for their system tests.
There was a problem hiding this comment.
I'm OK if its a follow-up, please file a ticket to dedupe these.
There was a problem hiding this comment.
This is b/554057686.
| import * as opentelemetry from '@opentelemetry/api'; | ||
| import {google} from '../protos/protos'; | ||
| import * as defer from 'p-defer'; | ||
| import * as crypto from 'node:crypto'; |
There was a problem hiding this comment.
This is great! Can you do this to other imports, here or in another PR?
There was a problem hiding this comment.
You mean the adding node:, right? I agree it's good practice now. I'll make a separate PR in a bit.
| // I don't like that these two files (this plus ".test") are duplicated | ||
| // across the two test structures, but because of the tangle of rootDirs | ||
| // and package.json "files", it's hard to avoid it. |
There was a problem hiding this comment.
I'm OK if its a follow-up, please file a ticket to dedupe these.
|
|
||
| const message = await new Promise<Message>((resolve, reject) => { | ||
| const timeout = setTimeout(() => reject(new Error('Timeout waiting for Avro record')), 15000); | ||
| subscription.once('message', (m: Message) => { |
There was a problem hiding this comment.
Sorry I didn't point it out before, there are several cases like this remaining in the PR. Can you please address those, too?
|
please address all the remaining listeners before submitting. |
Extracts system tests from the sample system tests in the original repo, and adds those to the handwritten/pubsub tree.