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(tpu): improving tpu tests #9679

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

fix(tpu): improving tpu tests #9679

wants to merge 8 commits into from

Conversation

TetyanaYahodska
Copy link
Contributor

@TetyanaYahodska TetyanaYahodska commented Nov 12, 2024

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added api: tpu Issues related to the Cloud TPU API. samples Issues that are directly related to samples. labels Nov 12, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 12, 2024
@TetyanaYahodska TetyanaYahodska marked this pull request as ready for review November 12, 2024 18:07
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 13, 2024
Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

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

good work. thank you for finding the solution.
a few minor refactoring comments. plus a question regarding discrepancy of different runners used for different test classes

tpu/src/test/java/tpu/CreateTpuIT.java Outdated Show resolved Hide resolved
OperationFuture mockFuture = mock(OperationFuture.class);
when(mockTpuClient.createNodeAsync(any(CreateNodeRequest.class)))
.thenReturn(mockFuture);
CreateTpuVm.createTpuVm(
Copy link
Contributor

Choose a reason for hiding this comment

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

please add assert to verify that the return value is one that is expected to be returned by createNodeAsync() call or whatever the code sample method returns.

Copy link
Contributor Author

@TetyanaYahodska TetyanaYahodska Nov 14, 2024

Choose a reason for hiding this comment

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

Since we are mocking TpuClient, we can expect that the method has been called but no resources have been created, so the return value of CreateTpuVm.createTpuVm() will be null. Based on this example

Mockito.mockStatic(ManagedKafkaClient.class)) {
we can check that a String is printed when the method is running. Should I add a print String to verify this? If we want to do E-2-E testing, we can move on to creating a real TpuClient and real resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to print. To your argument, since you control the return value you can ensure that the client library returns whatever you like. It is exactly the same as with e2e testing when you expect the valid not null response and you validate vs that response.
Note that not all code samples return the object they get from calling a client library method "as is". Some return only a field and others do a sequence of calls.

tpu/src/test/java/tpu/QueuedResourceIT.java Outdated Show resolved Hide resolved
OperationFuture mockFuture = mock(OperationFuture.class);
when(mockTpuClient.createQueuedResourceAsync(any(CreateQueuedResourceRequest.class)))
.thenReturn(mockFuture);
CreateQueuedResourceWithNetwork.createQueuedResourceWithNetwork(
Copy link
Contributor

Choose a reason for hiding this comment

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

please add assert to verify that the return value is one that is expected to be returned by createQueuedResourceAsync() call or whatever the code sample method returns.

Copy link
Contributor Author

@TetyanaYahodska TetyanaYahodska Nov 14, 2024

Choose a reason for hiding this comment

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

Since we are mocking TpuClient, we can expect that the method has been called but no resources have been created, so the return value of CreateQueuedResourceWithNetwork.createQueuedResourceWithNetwork() will be null. Based on this example

Mockito.mockStatic(ManagedKafkaClient.class)) {
we can check that a String is printed when the method is running. SShould I add a print String to verify this? If we want to do E-2-E testing, we can move on to creating a real TpuClient and real resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

See my response in another comment thread

when(mock(TpuClient.class)
.getQueuedResource(any(QueuedResourceName.class))).thenReturn(mockQueuedResource);

GetQueuedResource.getQueuedResource(PROJECT_ID, ZONE, NODE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

please add assert to verify that the return value is one that is expected to be returned by getQueuedResource() call or whatever the code sample method returns.

Copy link
Contributor Author

@TetyanaYahodska TetyanaYahodska Nov 14, 2024

Choose a reason for hiding this comment

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

Since we are mocking TpuClient, we can expect that the method has been called but no resources have been created before, so the return value of GetQueuedResource.getQueuedResource() will be null. Based on this example

Mockito.mockStatic(ManagedKafkaClient.class)) {
we can check that a String is printed when the method is running. Should I add a print like this to verify this? If we want to do E-2-E testing, we can move on to creating a real TpuClient and real resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

See my response in another comment thread

tpu/src/test/java/tpu/QueuedResourceIT.java Show resolved Hide resolved
tpu/src/test/java/tpu/TpuVmIT.java Outdated Show resolved Hide resolved
tpu/src/test/java/tpu/TpuVmIT.java Outdated Show resolved Hide resolved
tpu/src/test/java/tpu/TpuVmIT.java Outdated Show resolved Hide resolved

Node node = CreateTpuVm.createTpuVm(
PROJECT_ID, ZONE, NODE_NAME, TPU_TYPE, TPU_SOFTWARE_VERSION);
GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

please add assert to verify that the return value is one that is expected to be returned by getNode() call or whatever the code sample method returns.

Copy link
Contributor Author

@TetyanaYahodska TetyanaYahodska Nov 14, 2024

Choose a reason for hiding this comment

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

Since we are mocking TpuClient, we can expect that the method has been called but no resources have been created before, so the return value of GetTpuVm.getTpuVm() will be null. Based on this example

Mockito.mockStatic(ManagedKafkaClient.class)) {
we can check that a String is printed when the method is running. Should I add a print String to verify this? If we want to do E-2-E testing, we can move on to creating a real TpuClient and real resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

See my response in another comment thread

@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: tpu Issues related to the Cloud TPU API. kokoro:run Add this label to force Kokoro to re-run the tests. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants