Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

fix(test): testThrottlingBlocking flakyness fix #1775

Merged
merged 2 commits into from Aug 22, 2022
Merged

Conversation

diegomarquezp
Copy link
Contributor

Related to #1615
When BatcherImpl.sendOutstanding (method that calls callContext.withOption) is called from PushCurrentBatchRunnable, it uses
the batcher's own executor, causing the mockito capture to fail due to be in a different
thread from the one that originated add(). Other times, sendOutstanding will be called from the parent
thread (successful test, in this case from our newFixedThreadPool).
ALthough this is expected behavior, the argument captors do not work
when used in different threads. Mockito.verify() is the recommended way
of dealing with argument captors and happened to be the fix
Internally, verify() relies on thread safe(r) notifiers for when the captors have been interacted with.
When verifying flakiness, 100 runs in two threads were used with
bazel test //gax:com.google.api.gax.batching.BatcherImplTest --runs_per_test=100 --test_filter Throttling --jobs 2

Mockito.verify() implementation:
https://github.com/mockito/mockito/blob/2ded10ec704f2c93648d976031c2520a5a9b84aa/src/main/java/org/mockito/internal/MockitoCore.java#L183

When BatcherImpl.sendOutstanding (method that calls callContext.withOption) is called from PushCurrentBatchRunnable, it uses
the batcher's own executor, causing the mockito capture to fail due to be in a different
thread from the one that originated add(). Other times, sendOutstanding will be called from the parent
thread (successful test, in this case from our newFixedThreadPool).
ALthough this is expected behavior, the argument captors do not work
when used in different threads. Mockito.verify() is the recommended way
of dealing with argument captors and happened to be the fix
Internally, verify() relies on thread safe(r) notifiers for when the captors have been interacted with.
When verifying flakiness, 100 runs in two threads were used with
bazel test //gax:com.google.api.gax.batching.BatcherImplTest --runs_per_test=100 --test_filter Throttling --jobs 2

Mockito.verify() implementation:
https://github.com/mockito/mockito/blob/2ded10ec704f2c93648d976031c2520a5a9b84aa/src/main/java/org/mockito/internal/MockitoCore.java#L183
@diegomarquezp diegomarquezp requested review from a team as code owners August 16, 2022 19:02

// Mockito recommends using verify() as the ONLY recommended way to interact with Argument
// captors - otherwise it may incur in unexpected behaviour
Mockito.verify(callContext, Mockito.timeout(0)).withOption(key.capture(), value.capture());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the Mockito.timeout(0) if the time out value is 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not necessary. I removed it in a new commit

@sonarcloud
Copy link

sonarcloud bot commented Aug 16, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@blakeli0 blakeli0 left a comment

Choose a reason for hiding this comment

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

LGTM. Make sure the GraalVM test failure is not related to your changes though.

@diegomarquezp diegomarquezp merged commit e69393c into main Aug 22, 2022
@diegomarquezp diegomarquezp deleted the flaky-batcher-fix branch August 22, 2022 18:53
gcf-merge-on-green bot pushed a commit that referenced this pull request Aug 23, 2022
🤖 I have created a release *beep* *boop*
---


## [2.19.0](v2.18.7...v2.19.0) (2022-08-22)


### Features

* Add numeric enum support. ([#1743](#1743)) ([3f7628e](3f7628e))


### Bug Fixes

* **deps:** update dependency com.google.auth:google-auth-library-credentials to v1.10.0 ([#1768](#1768)) ([3f2188d](3f2188d))
* **deps:** update dependency com.google.auth:google-auth-library-credentials to v1.9.0 ([#1765](#1765)) ([103db3c](103db3c))
* **deps:** update dependency com.google.auth:google-auth-library-oauth2-http to v1.10.0 ([#1769](#1769)) ([0b1eb92](0b1eb92))
* **deps:** update dependency com.google.auth:google-auth-library-oauth2-http to v1.9.0 ([#1766](#1766)) ([2677f07](2677f07))
* **deps:** update dependency com.google.code.gson:gson to v2.9.1 ([#1757](#1757)) ([ea2a075](ea2a075))
* **deps:** update dependency com.google.protobuf:protobuf-bom to v3.21.5 ([#1772](#1772)) ([d7a48d1](d7a48d1))
* **deps:** update dependency io.grpc:grpc-bom to v1.48.1 ([#1763](#1763)) ([e5e4232](e5e4232))
* **deps:** update dependency org.graalvm.sdk:graal-sdk to v22.2.0 ([#1740](#1740)) ([ded44a6](ded44a6))
* **deps:** update dependency org.mockito:mockito-core to v4.7.0 ([#1774](#1774)) ([29678c8](29678c8))
* **deps:** update dependency org.threeten:threetenbp to v1.6.1 ([#1773](#1773)) ([d2c84e6](d2c84e6))
* **test:** testThrottlingBlocking flakyness fix ([#1775](#1775)) ([e69393c](e69393c))


### Documentation

* explaining UNIX environment is required ([#1760](#1760)) ([1d31e90](1d31e90))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
suztomo pushed a commit to googleapis/sdk-platform-java that referenced this pull request Dec 16, 2022
🤖 I have created a release *beep* *boop*
---


## [2.19.0](googleapis/gax-java@v2.18.7...v2.19.0) (2022-08-22)


### Features

* Add numeric enum support. ([#1743](googleapis/gax-java#1743)) ([fa87970](googleapis/gax-java@fa87970))


### Bug Fixes

* **deps:** update dependency com.google.auth:google-auth-library-credentials to v1.10.0 ([#1768](googleapis/gax-java#1768)) ([6008b0d](googleapis/gax-java@6008b0d))
* **deps:** update dependency com.google.auth:google-auth-library-credentials to v1.9.0 ([#1765](googleapis/gax-java#1765)) ([ba597b4](googleapis/gax-java@ba597b4))
* **deps:** update dependency com.google.auth:google-auth-library-oauth2-http to v1.10.0 ([#1769](googleapis/gax-java#1769)) ([db37c42](googleapis/gax-java@db37c42))
* **deps:** update dependency com.google.auth:google-auth-library-oauth2-http to v1.9.0 ([#1766](googleapis/gax-java#1766)) ([fe181b0](googleapis/gax-java@fe181b0))
* **deps:** update dependency com.google.code.gson:gson to v2.9.1 ([#1757](googleapis/gax-java#1757)) ([36a0136](googleapis/gax-java@36a0136))
* **deps:** update dependency com.google.protobuf:protobuf-bom to v3.21.5 ([#1772](googleapis/gax-java#1772)) ([c9a2a56](googleapis/gax-java@c9a2a56))
* **deps:** update dependency io.grpc:grpc-bom to v1.48.1 ([#1763](googleapis/gax-java#1763)) ([5535101](googleapis/gax-java@5535101))
* **deps:** update dependency org.graalvm.sdk:graal-sdk to v22.2.0 ([#1740](googleapis/gax-java#1740)) ([77f66d3](googleapis/gax-java@77f66d3))
* **deps:** update dependency org.mockito:mockito-core to v4.7.0 ([#1774](googleapis/gax-java#1774)) ([e192e0b](googleapis/gax-java@e192e0b))
* **deps:** update dependency org.threeten:threetenbp to v1.6.1 ([#1773](googleapis/gax-java#1773)) ([b9e4767](googleapis/gax-java@b9e4767))
* **test:** testThrottlingBlocking flakyness fix ([#1775](googleapis/gax-java#1775)) ([9aef46a](googleapis/gax-java@9aef46a))


### Documentation

* explaining UNIX environment is required ([#1760](googleapis/gax-java#1760)) ([1555924](googleapis/gax-java@1555924))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants