Skip to content

test(pubsub): [C09] await and fix Avro sample system tests - #9904

Draft
feywind wants to merge 1 commit into
c09/pubsub-delete-redundant-gapicfrom
c09/pubsub-fix-avro-samples-test
Draft

feywind wants to merge 1 commit into
c09/pubsub-delete-redundant-gapicfrom
c09/pubsub-fix-avro-samples-test

Conversation

@feywind

@feywind feywind commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes unawaited Avro sample system tests, JSON encoding, and schema cleanup.

Impact

Ensures Avro binary and JSON system tests execute and clean up.

Changes

  • Add missing await calls to publishAndListen('BINARY') and publishAndListen('JSON') in handwritten/pubsub/system-test/avro-samples.test.ts.
  • Create subscriptions with topic.createSubscription(subName) instead of calling pubsub.subscription(subName).get() on nonexistent subscriptions.
  • Encode and decode 'JSON' Avro messages using type.toString / type.fromString (keeping type.toBuffer / type.fromBuffer for 'BINARY').
  • Fix after() schema cleanup so resources.filterForCleanup inspects ISchema objects (which carry .name) and deletes matching schemas via pubsub.schema(x.name!).delete().
  • Remove unused Message import and replace any annotations with typed ISchema and Province definitions.

Testing

  • Ran build/system-test/avro-samples.test.js against the official Cloud Pub/Sub Emulator (0.8.38): 3 passing (1s).
  • Ran build/system-test/avro-samples.test.js against live Cloud Pub/Sub: 3 passing (28s), and confirmed zero leftover topics, subscriptions, or schemas after cleanup.
  • Ran pnpm --dir handwritten/pubsub test: passed.
  • Ran pnpm --dir handwritten/pubsub exec eslint --no-ignore system-test/avro-samples.test.ts: 0 errors, 0 warnings.

Alternatives

  • Leaving publishAndListen('BINARY') and publishAndListen('JSON') unawaited lets both tests silently pass in 0 ms without testing Avro encoding or surfacing errors.

@product-auto-label product-auto-label Bot added api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples. labels Nov 18, 2026
@feywind
feywind added this pull request to stack #9907 November 18, 2026 22:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Avro samples system tests to support both BINARY and JSON encodings, introduces the Province interface for better typing, and ensures proper cleanup of schemas. It also fixes the tests by correctly awaiting the publishAndListen calls. The review feedback recommends using standard type assertions (as Province) instead of passing type arguments directly to fromBuffer and fromString methods, as these methods are not defined as generics in standard Avro typings and could cause compilation issues.

Comment on lines +103 to +106
const result =
encoding === 'BINARY'
? type.fromBuffer<Province>(message.data)
: type.fromString<Province>(message.data.toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Passing type arguments directly to type.fromBuffer and type.fromString (e.g., type.fromBuffer<Province>(...)) is not standard for avro-js or avsc type definitions, as these methods are typically not declared as generic in their typings. This works currently only because avro-js lacks strict typings in this context (making type resolve to any), but it will cause compilation errors if strict typings are introduced or if the project switches to avsc.

Using a standard type assertion (as Province) is safer and more robust.

Suggested change
const result =
encoding === 'BINARY'
? type.fromBuffer<Province>(message.data)
: type.fromString<Province>(message.data.toString());
const result =
encoding === 'BINARY'
? (type.fromBuffer(message.data) as Province)
: (type.fromString(message.data.toString()) as Province);


const reader = avro.parse(fetchedSchema.definition!);
const result = reader.fromBuffer(message.data) as any;
const result = reader.fromBuffer<Province>(message.data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid passing type arguments directly to reader.fromBuffer as it is not defined as a generic method in standard Avro typings. Use a standard type assertion (as Province) instead.

Suggested change
const result = reader.fromBuffer<Province>(message.data);
const result = reader.fromBuffer(message.data) as Province;

@feywind

feywind commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

This is just preliminary test-run work on this one.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant